Skip to content

BUG: fix AttributeError raised in libreduction #29100

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 5 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 10 additions & 6 deletions pandas/_libs/reduction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ cdef class SeriesBinGrouper:
self.f = f

values = series.values
if not values.flags.c_contiguous:
if util.is_array(values) and not values.flags.c_contiguous:
# e.g. Categorical has no `flags` attribute
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work with Categorical otherwise (the BinGrouper)? do we need tests here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have tests that get here with Categorical and IntegerArray.

values = values.copy('C')
self.arr = values
self.typ = series._constructor
Expand All @@ -230,7 +231,8 @@ cdef class SeriesBinGrouper:
values = dummy.values
if values.dtype != self.arr.dtype:
raise ValueError('Dummy array must be same dtype')
if not values.flags.contiguous:
if util.is_array(values) and not values.flags.contiguous:
# e.g. Categorical has no `flags` attribute
values = values.copy()
index = dummy.index.values
if not index.flags.contiguous:
Expand Down Expand Up @@ -356,7 +358,8 @@ cdef class SeriesGrouper:
if (dummy.dtype != self.arr.dtype
and values.dtype != self.arr.dtype):
raise ValueError('Dummy array must be same dtype')
if not values.flags.contiguous:
if util.is_array(values) and not values.flags.contiguous:
# e.g. Categorical has no `flags` attribute
values = values.copy()
index = dummy.index.values
if not index.flags.contiguous:
Expand Down Expand Up @@ -467,12 +470,13 @@ cdef class Slider:
char *orig_data

def __init__(self, object values, object buf):
assert(values.ndim == 1)
assert (values.ndim == 1)

if not values.flags.contiguous:
if util.is_array(values) and not values.flags.contiguous:
# e.g. Categorical has no `flags` attribute
values = values.copy()

assert(values.dtype == buf.dtype)
assert (values.dtype == buf.dtype)
self.values = values
self.buf = buf
self.stride = values.strides[0]
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def aggregate(self, func=None, *args, **kwargs):

try:
return self._python_agg_general(func, *args, **kwargs)
except AssertionError:
except (AssertionError, AttributeError):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what hits AttributeError here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have tests that raise AttributeError here (in master) when a Categorical or IntegerArray is passed to SeriesBinGrouper.

raise
except Exception:
result = self._aggregate_named(func, *args, **kwargs)
Expand Down