def parseSeries(htmlArr): seriesList = [] for s in htmlArr: if len(s) == 3: title = s[0].contents[0].contents[0] year = s[2].contents[0] songs = parseTable(s[1]) seriesList.append(sr.Series(title, "", year, songs)) else: title = s[0].contents[0].contents[0] altTitle = s[1].contents[0].contents[0] year = s[3].contents[0] songs = parseTable(s[2]) seriesList.append(sr.Series(title, altTitle, year, songs)) return seriesList
def _getitem_iloc(self, key): if not isinstance(key, tuple): key = (key, None) if isinstance(key[0], int) and isinstance(key[1], int): return self._dataframe.getValue(key[0], key[1]) k = key[0] if isinstance(k, int): if k < 0: k = self.shape[0] + k rowkey = k elif isinstance(k, slice): sidx = 0 if k.start is None else k.start if sidx < 0: sidx = self.shape[0] + sidx eidx = self.shape[0] - 1 if k.stop is None else k.stop - 1 if eidx < 0: eidx = self.shape[0] + eidx step = 1 if k.step is None else k.step rowkey = Range(sidx, eidx, step) elif isinstance(k, list): rowkey = k else: return None k = key[1] if k is None: colkey = Range(0, self.shape[1] - 1, 1) else: if isinstance(k, int): sidx = k if sidx < 0: sidx = self.shape[1] + sidx eidx = sidx step = 1 colkey = Range(sidx, eidx, step) elif isinstance(k, slice): sidx = 0 if k.start is None else k.start if sidx < 0: sidx = self.shape[1] + sidx eidx = self.shape[1] - 1 if k.stop is None else k.stop - 1 if eidx < 0: eidx = self.shape[1] + eidx step = 1 if k.step is None else k.step colkey = Range(sidx, eidx, step) elif isinstance(k, list): colkey = k else: return None r = self._dataframe.select(rowkey, colkey) if r is None: return None if isinstance(r, MISeries): r = series.Series(series=r) else: r = DataFrame(dataframe=r) return r
def min(self): ''' Compute minimum of group. ''' r = self._groupby.min() if isinstance(r, MIDataFrame): return dataframe.DataFrame(dataframe=r) else: return series.Series(series=r)
def count(self): ''' Compute count of group. ''' r = self._groupby.count() if isinstance(r, MIDataFrame): return dataframe.DataFrame(dataframe=r) else: return series.Series(series=r)
def sum(self): ''' Compute sum of groups. ''' r = self._groupby.sum() if isinstance(r, MIDataFrame): return dataframe.DataFrame(dataframe=r) else: return series.Series(series=r)
def std(self): ''' Compute standard deviation of groups. ''' r = self._groupby.median() if isinstance(r, MIDataFrame): return dataframe.DataFrame(dataframe=r) else: return series.Series(series=r)
def testBasic(self): """Test basic filter operation""" data=''' From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001 From: Simon Glass <*****@*****.**> Date: Thu, 28 Apr 2011 09:58:51 -0700 Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support This adds functions to enable/disable clocks and reset to on-chip peripherals. BUG=chromium-os:13875 TEST=build U-Boot for Seaboard, boot Change-Id: I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413 Review URL: http://codereview.chromium.org/6900006 Signed-off-by: Simon Glass <*****@*****.**> --- arch/arm/cpu/armv7/tegra2/Makefile | 2 +- arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++---- arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++ ''' expected=''' From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001 From: Simon Glass <*****@*****.**> Date: Thu, 28 Apr 2011 09:58:51 -0700 Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support This adds functions to enable/disable clocks and reset to on-chip peripherals. Signed-off-by: Simon Glass <*****@*****.**> --- arch/arm/cpu/armv7/tegra2/Makefile | 2 +- arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++---- arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++ ''' out = '' inhandle, inname = tempfile.mkstemp() infd = os.fdopen(inhandle, 'w') infd.write(data) infd.close() exphandle, expname = tempfile.mkstemp() expfd = os.fdopen(exphandle, 'w') expfd.write(expected) expfd.close() patchstream.FixPatch(None, inname, series.Series(), None) rc = os.system('diff -u %s %s' % (inname, expname)) self.assertEqual(rc, 0) os.remove(inname) os.remove(expname)
def get_group(self, name): ''' Get a group :param name: The name of the group :return: The group ''' r = self._groupby.getGroup(name) if isinstance(r, MIDataFrame): return dataframe.DataFrame(dataframe=r) else: return series.Series(series=r)
def quantile(self, q): ''' Return values at the given quantile. :param q: (*float*) Value between 0 <= q <= 1, the quantile(s) to compute. :returns: Series or DataFrame ''' r = self._groupby.percentile(q) if isinstance(r, MIDataFrame): return dataframe.DataFrame(dataframe=r) else: return series.Series(series=r) ########################################################
def testBasic(self): """Test basic filter operation""" data = ''' From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001 From: Simon Glass <*****@*****.**> Date: Thu, 28 Apr 2011 09:58:51 -0700 Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support This adds functions to enable/disable clocks and reset to on-chip peripherals. cmd/pci.c:152:11: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘u64 {aka long unsigned int}’ [-Wformat=] BUG=chromium-os:13875 TEST=build U-Boot for Seaboard, boot Change-Id: I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413 Review URL: http://codereview.chromium.org/6900006 Signed-off-by: Simon Glass <*****@*****.**> --- arch/arm/cpu/armv7/tegra2/Makefile | 2 +- arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++---- arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++ ''' expected = '''Message-Id: <19991231235959.0.I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413@changeid> From 656c9a8c31fa65859d924cd21da920d6ba537fad Mon Sep 17 00:00:00 2001 From: Simon Glass <*****@*****.**> Date: Thu, 28 Apr 2011 09:58:51 -0700 Subject: [PATCH (resend) 3/7] Tegra2: Add more clock support This adds functions to enable/disable clocks and reset to on-chip peripherals. cmd/pci.c:152:11: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘u64 {aka long unsigned int}’ [-Wformat=] Signed-off-by: Simon Glass <*****@*****.**> --- arch/arm/cpu/armv7/tegra2/Makefile | 2 +- arch/arm/cpu/armv7/tegra2/ap20.c | 57 ++---- arch/arm/cpu/armv7/tegra2/clock.c | 163 +++++++++++++++++ ''' out = '' inhandle, inname = tempfile.mkstemp() infd = os.fdopen(inhandle, 'w', encoding='utf-8') infd.write(data) infd.close() exphandle, expname = tempfile.mkstemp() expfd = os.fdopen(exphandle, 'w', encoding='utf-8') expfd.write(expected) expfd.close() # Normally by the time we call FixPatch we've already collected # metadata. Here, we haven't, but at least fake up something. # Set the "count" to -1 which tells FixPatch to use a bogus/fixed # time for generating the Message-Id. com = commit.Commit('') com.change_id = 'I80fe1d0c0b7dd10aa58ce5bb1d9290b6664d5413' com.count = -1 patchstream.FixPatch(None, inname, series.Series(), com) rc = os.system('diff -u %s %s' % (inname, expname)) self.assertEqual(rc, 0) os.remove(inname) os.remove(expname)
def _getitem_loc(self, key): if not isinstance(key, tuple): key = (key, None) k = key[0] rkeys = key[0] if isinstance(k, slice): sidx = 0 if k.start is None else self._index.index(k.start) if sidx < 0: raise KeyError(key) eidx = self.shape[0] - 1 if k.stop is None else self._index.index( k.stop) if eidx < 0: raise KeyError(key) step = 1 if k.step is None else k.step rowkey = Range(sidx, eidx, step) else: rloc = self._index.get_loc(k, outkeys=True) if isinstance(rloc, tuple): rowkey = rloc[0] rkeys = rloc[1] else: rowkey = rloc rkeys = None if len(rowkey) == 0: raise KeyError(key) k = key[1] if k is None: colkey = Range(0, self.shape[1] - 1, 1) else: if isinstance(k, slice): sidx = 0 if k.start is None else self.columns.indexOfName( k.start) if sidx < 0: raise KeyError(key) eidx = self.shape[ 1] - 1 if k.stop is None else self.columns.indexOfName( k.stop) if eidx < 0: raise KeyError(key) step = 1 if k.step is None else k.step colkey = Range(sidx, eidx, step) elif isinstance(k, list): colkey = self.columns.indexOfName(k) elif isinstance(k, basestring): col = self.columns.indexOfName(k) if col < 0: raise KeyError(key) colkey = [col] else: return None if isinstance(rowkey, (int, Range)): r = self._dataframe.select(rowkey, colkey) else: if isinstance(colkey, Range): ncol = colkey.length() else: ncol = len(colkey) if len(rowkey) == 1 and ncol == 1: if isinstance(colkey, Range): return self._dataframe.getValue(rowkey[0], colkey.first()) else: return self._dataframe.getValue(rowkey[0], colkey[0]) if rkeys is None: r = self._dataframe.select(rowkey, colkey) else: if not isinstance(rkeys, list): rkeys = [rkeys] r = self._dataframe.select(rkeys, rowkey, colkey) if r is None: return None if isinstance(r, MISeries): r = series.Series(series=r) else: r = DataFrame(dataframe=r) return r
def __getitem__(self, key): if isinstance(key, basestring): data = self._dataframe.getColumnData(key) if data is None: return data idx = self._index[:] r = series.Series(np.array(data), idx, key) return r hascolkey = True if isinstance(key, tuple): ridx = key[0] cidx = key[1] if isinstance(ridx, int) and isinstance(cidx, int): if ridx < 0: ridx = self.shape[0] + ridx if cidx < 0: cidx = self.shape[1] + cidx return self._dataframe.getValue(ridx, cidx) elif isinstance(ridx, int) and isinstance(cidx, basestring): if ridx < 0: ridx = self.shape[0] + ridx return self._dataframe.getValue(ridx, cidx) else: key = (key, slice(None)) hascolkey = False k = key[0] if isinstance(k, Index): k = k.data if isinstance(k, int): if k < 0: k = self.shape[0] + k rowkey = k elif isinstance(k, basestring): sidx = self._index.index(k) if sidx < 0: return None eidx = sidx step = 1 rowkey = Range(sidx, eidx, step) elif isinstance(k, slice): if isinstance(k.start, basestring): sidx = self._index.index(k.start) if sidx < 0: sidx = 0 else: sidx = 0 if k.start is None else k.start if sidx < 0: sidx = self.shape[0] + sidx if isinstance(k.stop, basestring): eidx = self._index.index(k.stop) if eidx < 0: eidx = self.shape[0] + eidx else: eidx = self.shape[0] - 1 if k.stop is None else k.stop - 1 if eidx < 0: eidx = self.shape[0] + eidx step = 1 if k.step is None else k.step rowkey = Range(sidx, eidx, step) elif isinstance(k, (list, tuple, np.NDArray, series.Series)): if isinstance(k[0], (int, bool)): if isinstance(k, (list, tuple)): rowkey = k else: rowkey = k.asarray() else: tlist = [] for tstr in k: idx = self._index.index(tstr) if idx >= 0: tlist.append(idx) rowkey = tlist else: rowkey = self._index.get_loc(k) if not hascolkey: colkey = Range(0, self.shape[1] - 1, 1) else: k = key[1] if isinstance(k, int): sidx = k if sidx < 0: sidx = self.shape[1] + sidx eidx = sidx step = 1 colkey = Range(sidx, eidx, step) elif isinstance(k, slice): sidx = 0 if k.start is None else k.start if sidx < 0: sidx = self.shape[1] + sidx eidx = self.shape[1] - 1 if k.stop is None else k.stop - 1 if eidx < 0: eidx = self.shape[1] + eidx step = 1 if k.step is None else k.step colkey = Range(sidx, eidx, step) elif isinstance(k, list): if isinstance(k[0], int): colkey = k else: colkey = self.columns.indexOfName(k) elif isinstance(k, basestring): col = self.columns.indexOf(k) colkey = Range(col, col + 1, 1) else: return None r = self._dataframe.select(rowkey, colkey) if r is None: return None if isinstance(r, MISeries): r = series.Series(series=r) else: r = DataFrame(dataframe=r) return r
def get_dtypes(self): colnames = list(self.columns.getNames()) datatypes = list(self.columns.getDataTypes()) r = series.Series(datatypes, colnames, 'DataTypes') return r
# Random TV episode chooser for people who just can't decide import random import series as s import interface as i series = s.Series() ui = i.Interface(series.series_dict) print("\nBored? Indecisive? No problem.") ui.print_menu() prompt = ''' Enter the series you want or Q to quit or ? to repeat the instructions: ''' while True: user_input = input(prompt).lower() if user_input == 'q': print("\nSee you next time!\n") break elif user_input == '?': ui.print_menu() continue # Choose a random series if user can't decide. elif user_input == 'x':