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
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
19 changes: 12 additions & 7 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 @@ -332,7 +334,8 @@ cdef class SeriesGrouper:
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
values = values.copy('C')
self.arr = values
self.typ = series._constructor
Expand All @@ -356,7 +359,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 +471,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