Skip to content

Commit 5cc71a8

Browse files
committed
Merge pull request #10976 from behzadnouri/bin-gr
CLN: removes BinGrouper kind of cython methods
2 parents 7ca2190 + 02ba722 commit 5cc71a8

File tree

5 files changed

+184
-2242
lines changed

5 files changed

+184
-2242
lines changed

pandas/core/groupby.py

+15-33
Original file line numberDiff line numberDiff line change
@@ -1793,17 +1793,25 @@ def indices(self):
17931793
def group_info(self):
17941794
ngroups = self.ngroups
17951795
obs_group_ids = np.arange(ngroups)
1796-
comp_ids = np.repeat(np.arange(ngroups), np.diff(np.r_[0, self.bins]))
1796+
rep = np.diff(np.r_[0, self.bins])
1797+
1798+
if ngroups == len(self.bins):
1799+
comp_ids = np.repeat(np.arange(ngroups), rep)
1800+
else:
1801+
comp_ids = np.repeat(np.r_[-1, np.arange(ngroups)], rep)
1802+
17971803
return comp_ids, obs_group_ids, ngroups
17981804

17991805
@cache_readonly
18001806
def ngroups(self):
1801-
return len(self.binlabels)
1807+
return len(self.result_index)
18021808

18031809
@cache_readonly
18041810
def result_index(self):
1805-
mask = self.binlabels.asi8 == tslib.iNaT
1806-
return self.binlabels[~mask]
1811+
if len(self.binlabels) != 0 and isnull(self.binlabels[0]):
1812+
return self.binlabels[1:]
1813+
1814+
return self.binlabels
18071815

18081816
@property
18091817
def levels(self):
@@ -1839,40 +1847,14 @@ def size(self):
18391847
#----------------------------------------------------------------------
18401848
# cython aggregation
18411849

1842-
_cython_functions = {
1843-
'add': 'group_add_bin',
1844-
'prod': 'group_prod_bin',
1845-
'mean': 'group_mean_bin',
1846-
'min': 'group_min_bin',
1847-
'max': 'group_max_bin',
1848-
'var': 'group_var_bin',
1849-
'ohlc': 'group_ohlc',
1850-
'first': {
1851-
'name': 'group_nth_bin',
1852-
'f': lambda func, a, b, c, d: func(a, b, c, d, 1)
1853-
},
1854-
'last': 'group_last_bin',
1855-
'count': 'group_count_bin',
1856-
}
1850+
_cython_functions = {'ohlc': 'group_ohlc'}
1851+
_cython_functions.update(BaseGrouper._cython_functions)
1852+
_cython_functions.pop('median')
18571853

18581854
_name_functions = {
18591855
'ohlc': lambda *args: ['open', 'high', 'low', 'close']
18601856
}
18611857

1862-
def _aggregate(self, result, counts, values, agg_func, is_numeric=True):
1863-
1864-
if values.ndim > 3:
1865-
# punting for now
1866-
raise NotImplementedError("number of dimensions is currently "
1867-
"limited to 3")
1868-
elif values.ndim > 2:
1869-
for i, chunk in enumerate(values.transpose(2, 0, 1)):
1870-
agg_func(result[:, :, i], counts, chunk, self.bins)
1871-
else:
1872-
agg_func(result, counts, values, self.bins)
1873-
1874-
return result
1875-
18761858
def agg_series(self, obj, func):
18771859
dummy = obj[:0]
18781860
grouper = lib.SeriesBinGrouper(obj, func, self.bins, dummy)

0 commit comments

Comments
 (0)