Skip to content

CLN: catch less inside try/except #28203

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 4 commits into from
Aug 30, 2019
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
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
17 changes: 9 additions & 8 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,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 +263,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 +312,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 +683,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