-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: preserve categorical & sparse types when grouping / pivot & preserve dtypes on ufuncs #26550
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
Changes from all commits
5bec6b3
d1490a2
561e960
28be4d9
d6db2ea
7c29393
0662f2b
c75461c
86090bf
4bd486e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1919,25 +1919,6 @@ def empty(self): | |
# ---------------------------------------------------------------------- | ||
# Array Interface | ||
|
||
# This is also set in IndexOpsMixin | ||
# GH#23114 Ensure ndarray.__op__(DataFrame) returns NotImplemented | ||
__array_priority__ = 1000 | ||
|
||
def __array__(self, dtype=None): | ||
return com.values_from_object(self) | ||
|
||
def __array_wrap__(self, result, context=None): | ||
d = self._construct_axes_dict(self._AXIS_ORDERS, copy=False) | ||
return self._constructor(result, **d).__finalize__(self) | ||
|
||
# ideally we would define this to avoid the getattr checks, but | ||
# is slower | ||
# @property | ||
# def __array_interface__(self): | ||
# """ provide numpy array interface method """ | ||
# values = self.values | ||
# return dict(typestr=values.dtype.str,shape=values.shape,data=values) | ||
|
||
def to_dense(self): | ||
""" | ||
Return dense representation of NDFrame (as opposed to sparse). | ||
|
@@ -5693,6 +5674,11 @@ def astype(self, dtype, copy=True, errors='raise', **kwargs): | |
**kwargs) | ||
return self._constructor(new_data).__finalize__(self) | ||
|
||
if not results: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What case hits this? I'm not immediately seeing it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. empty frames :-> |
||
if copy: | ||
self = self.copy() | ||
return self | ||
|
||
# GH 19920: retain column metadata after concat | ||
result = pd.concat(results, axis=1, copy=False) | ||
result.columns = self.columns | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,12 +156,19 @@ def _cython_agg_blocks(self, how, alt=None, numeric_only=True, | |
|
||
obj = self.obj[data.items[locs]] | ||
s = groupby(obj, self.grouper) | ||
result = s.aggregate(lambda x: alt(x, axis=self.axis)) | ||
try: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's this for? Not immediately obvious the link between this and the overall PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this handles blocks that return NotImplementedError and then cann't be aggregated, e.g. Categoricals with string categories, aggregating with mean for exampel (and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you give an example? I'm also having trouble seeing this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If those return NotImplementedError can we limit the scope of the catching to just that? |
||
result = s.aggregate(lambda x: alt(x, axis=self.axis)) | ||
except Exception: | ||
# we may have an exception in trying to aggregate | ||
# continue and exclude the block | ||
pass | ||
|
||
finally: | ||
|
||
dtype = block.values.dtype | ||
|
||
# see if we can cast the block back to the original dtype | ||
result = block._try_coerce_and_cast_result(result) | ||
result = block._try_coerce_and_cast_result(result, dtype=dtype) | ||
newb = block.make_block(result) | ||
|
||
new_items.append(locs) | ||
|
Uh oh!
There was an error while loading. Please reload this page.