-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
API: ExtensionDtype._is_numeric #22345
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 2 commits
5064217
50de326
1d96d22
db9af36
a3fdc2a
fc34131
2779419
e813855
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 |
|---|---|---|
|
|
@@ -67,3 +67,16 @@ def test_groupby_extension_apply(self, data_for_grouping, op): | |
| df.groupby("B").A.apply(op) | ||
| df.groupby("A").apply(op) | ||
| df.groupby("A").B.apply(op) | ||
|
|
||
| def test_in_numeric_groupby(self, data_for_grouping): | ||
| df = pd.DataFrame({"A": [1, 1, 2, 2, 3, 3, 1, 4], | ||
| "B": data_for_grouping, | ||
| "C": [1, 1, 1, 1, 1, 1, 1, 1]}) | ||
| result = df.groupby("A").sum().columns | ||
|
Member
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. how does this test pass? (I thought reductions did not yet work for EAs?)
Contributor
Author
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. I wonder if it's going through the fallback
Member
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. Yeah, so reductions for Series fail (no |
||
|
|
||
| if data_for_grouping.dtype._is_numeric: | ||
| expected = pd.Index(['B', 'C']) | ||
| else: | ||
| expected = pd.Index(['C']) | ||
|
|
||
| tm.assert_index_equal(result, expected) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,3 +67,7 @@ def test_no_values_attribute(self, data): | |
| # code, disallowing this for now until solved | ||
| assert not hasattr(data, 'values') | ||
| assert not hasattr(data, '_values') | ||
|
|
||
| def test_is_numeric_honored(self, data): | ||
| result = pd.Series(data) | ||
| assert result._data.blocks[0].is_numeric is data.dtype._is_numeric | ||
|
Member
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. Maybe you can also test It would be nice if this would also work for
Member
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.
ah, that is done below |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I ran into this same issue when I was testing out a similar implementation.
I got around it by passing the argument
ndim=self.ndimto themake_blockfunction on line 664 above, which seems to get the job done and passes all relevant tests, though I didn't run the entire test suite. Not familiar enough with this code though to say if that's a better (or even adequate) workaround.For what it's worth, it looks like this
ndiminference inNonConsolidatableMixInis where things start to go wrong, at least for the length 1Seriescase:pandas/pandas/core/internals/blocks.py
Lines 1780 to 1785 in cf70d11
Again, not familiar enough with this code to immediately see a fix, but maybe this is helpful to someone with more knowledge of this code than me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems better.