Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 0 additions & 4 deletions pandas/_libs/reduction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,6 @@ cdef class SeriesBinGrouper:
islider.advance(group_size)
vslider.advance(group_size)

except:
raise
finally:
# so we don't free the wrong memory
islider.reset()
Expand Down Expand Up @@ -425,8 +423,6 @@ cdef class SeriesGrouper:

group_size = 0

except:
raise
finally:
# so we don't free the wrong memory
islider.reset()
Expand Down
26 changes: 11 additions & 15 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@
from pandas.core.frame import DataFrame
from pandas.core.generic import ABCDataFrame, ABCSeries, NDFrame, _shared_docs
from pandas.core.groupby import base
from pandas.core.groupby.groupby import (
GroupBy,
_apply_docs,
_transform_template,
groupby,
)
from pandas.core.groupby.groupby import GroupBy, _apply_docs, _transform_template
from pandas.core.index import Index, MultiIndex, _all_indexes_same
import pandas.core.indexes.base as ibase
from pandas.core.internals import BlockManager, make_block
Expand Down Expand Up @@ -174,7 +169,7 @@ def _cython_agg_blocks(self, how, alt=None, numeric_only=True, min_count=-1):

# call our grouper again with only this block
obj = self.obj[data.items[locs]]
s = groupby(obj, self.grouper)
s = obj.groupby(self.grouper)
try:
result = s.aggregate(lambda x: alt(x, axis=self.axis))
except TypeError:
Expand Down Expand Up @@ -242,15 +237,18 @@ def aggregate(self, func, *args, **kwargs):
# grouper specific aggregations
if self.grouper.nkeys > 1:
return self._python_agg_general(func, *args, **kwargs)
elif args or kwargs:
result = self._aggregate_generic(func, *args, **kwargs)
else:

# try to treat as if we are passing a list
try:
assert not args and not kwargs
result = self._aggregate_multiple_funcs(
[func], _level=_level, _axis=self.axis
)

except Exception:
result = self._aggregate_generic(func)
else:
result.columns = Index(
result.columns.levels[0], name=self._selected_obj.columns.name
)
Expand All @@ -260,8 +258,6 @@ def aggregate(self, func, *args, **kwargs):
# values. concat no longer converts DataFrame[Sparse]
# to SparseDataFrame, so we do it here.
result = SparseDataFrame(result._data)
except Exception:
result = self._aggregate_generic(func, *args, **kwargs)

if not self.as_index:
self._insert_inaxis_grouper_inplace(result)
Expand Down Expand Up @@ -311,10 +307,10 @@ def _aggregate_item_by_item(self, func, *args, **kwargs):
cannot_agg = []
errors = None
for item in obj:
try:
data = obj[item]
colg = SeriesGroupBy(data, selection=item, grouper=self.grouper)
data = obj[item]
colg = SeriesGroupBy(data, selection=item, grouper=self.grouper)

try:
cast = self._transform_should_cast(func)

result[item] = colg.aggregate(func, *args, **kwargs)
Expand Down Expand Up @@ -682,7 +678,7 @@ def _transform_item_by_item(self, obj, wrapper):

return DataFrame(output, index=obj.index, columns=columns)

def filter(self, func, dropna=True, *args, **kwargs): # noqa
def filter(self, func, dropna=True, *args, **kwargs):
"""
Return a copy of a DataFrame excluding elements from groups that
do not satisfy the boolean criterion specified by func.
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,8 @@ def curried(x):
# mark this column as an error
try:
return self._aggregate_item_by_item(name, *args, **kwargs)
except (AttributeError):
except AttributeError:
# e.g. SparseArray has no flags attr
raise ValueError

return wrapper
Expand Down