Skip to content

CLN: removes BinGrouper kind of cython methods #10976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 15 additions & 33 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1793,17 +1793,25 @@ def indices(self):
def group_info(self):
ngroups = self.ngroups
obs_group_ids = np.arange(ngroups)
comp_ids = np.repeat(np.arange(ngroups), np.diff(np.r_[0, self.bins]))
rep = np.diff(np.r_[0, self.bins])

if ngroups == len(self.bins):
comp_ids = np.repeat(np.arange(ngroups), rep)
else:
comp_ids = np.repeat(np.r_[-1, np.arange(ngroups)], rep)

return comp_ids, obs_group_ids, ngroups

@cache_readonly
def ngroups(self):
return len(self.binlabels)
return len(self.result_index)

@cache_readonly
def result_index(self):
mask = self.binlabels.asi8 == tslib.iNaT
return self.binlabels[~mask]
if len(self.binlabels) != 0 and isnull(self.binlabels[0]):
return self.binlabels[1:]

return self.binlabels

@property
def levels(self):
Expand Down Expand Up @@ -1839,40 +1847,14 @@ def size(self):
#----------------------------------------------------------------------
# cython aggregation

_cython_functions = {
'add': 'group_add_bin',
'prod': 'group_prod_bin',
'mean': 'group_mean_bin',
'min': 'group_min_bin',
'max': 'group_max_bin',
'var': 'group_var_bin',
'ohlc': 'group_ohlc',
'first': {
'name': 'group_nth_bin',
'f': lambda func, a, b, c, d: func(a, b, c, d, 1)
},
'last': 'group_last_bin',
'count': 'group_count_bin',
}
_cython_functions = {'ohlc': 'group_ohlc'}
_cython_functions.update(BaseGrouper._cython_functions)
_cython_functions.pop('median')

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

def _aggregate(self, result, counts, values, agg_func, is_numeric=True):

if values.ndim > 3:
# punting for now
raise NotImplementedError("number of dimensions is currently "
"limited to 3")
elif values.ndim > 2:
for i, chunk in enumerate(values.transpose(2, 0, 1)):
agg_func(result[:, :, i], counts, chunk, self.bins)
else:
agg_func(result, counts, values, self.bins)

return result

def agg_series(self, obj, func):
dummy = obj[:0]
grouper = lib.SeriesBinGrouper(obj, func, self.bins, dummy)
Expand Down
Loading