-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: add groupby & reduce support to EA #22762
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
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
90fb20e
ENH: add groupby & reduce support to EA
jreback 63899aa
don't need record=True
jreback 05f27a1
dispatch to Index types on _reduce
jreback 9dbbe51
handle min/max correctly for datetimelikes
jreback d4c0a3e
share doc-string with base class
jreback bb3f37c
remove more uneeded doc-strings
jreback e7fbe0f
simplify EA._reduce
jreback fddf938
fix categorical
jreback 49efedf
make _reduce an always defined method on Base; raise TypeError if inv…
jreback 371ab54
pass mask to nanops
jreback d94b85e
review comments
jreback 6774791
cleanup
jreback 6699080
doc
jreback 29c3cf7
lint issue
jreback 0fdaf68
comments
jreback 08f5830
fix test
jreback 3e763c4
comments
jreback b543386
add op tests for reduction result dtype
jreback b808778
remove xfails on frame arithmetic ops comparisons
jreback 2b3d96f
remove groupby overrides
jreback 3037ccd
format docstring
jorisvandenbossche b872607
add test ensuring mean always gives float
jorisvandenbossche aeaf5f3
add prod to list of type preserving reductions
jorisvandenbossche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import warnings | ||
import pytest | ||
import pandas.util.testing as tm | ||
import pandas as pd | ||
from .base import BaseExtensionTests | ||
|
||
|
||
class BaseReduceTests(BaseExtensionTests): | ||
""" | ||
Reduction specific tests. Generally these only | ||
make sense for numeric/boolean operations. | ||
""" | ||
def check_reduce(self, s, op_name, skipna): | ||
result = getattr(s, op_name)(skipna=skipna) | ||
expected = getattr(s.astype('float64'), op_name)(skipna=skipna) | ||
tm.assert_almost_equal(result, expected) | ||
|
||
|
||
class BaseNoReduceTests(BaseReduceTests): | ||
""" we don't define any reductions """ | ||
|
||
@pytest.mark.parametrize('skipna', [True, False]) | ||
def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna): | ||
op_name = all_numeric_reductions | ||
s = pd.Series(data) | ||
|
||
with pytest.raises(TypeError): | ||
getattr(s, op_name)(skipna=skipna) | ||
|
||
@pytest.mark.parametrize('skipna', [True, False]) | ||
def test_reduce_series_boolean(self, data, all_boolean_reductions, skipna): | ||
op_name = all_boolean_reductions | ||
s = pd.Series(data) | ||
|
||
with pytest.raises(TypeError): | ||
getattr(s, op_name)(skipna=skipna) | ||
|
||
|
||
class BaseNumericReduceTests(BaseReduceTests): | ||
|
||
@pytest.mark.parametrize('skipna', [True, False]) | ||
def test_reduce_series(self, data, all_numeric_reductions, skipna): | ||
op_name = all_numeric_reductions | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
s = pd.Series(data) | ||
|
||
# min/max with empty produce numpy warnings | ||
with warnings.catch_warnings(): | ||
warnings.simplefilter("ignore", RuntimeWarning) | ||
self.check_reduce(s, op_name, skipna) | ||
|
||
|
||
class BaseBooleanReduceTests(BaseReduceTests): | ||
|
||
@pytest.mark.parametrize('skipna', [True, False]) | ||
def test_reduce_series(self, data, all_boolean_reductions, skipna): | ||
op_name = all_boolean_reductions | ||
s = pd.Series(data) | ||
self.check_reduce(s, op_name, skipna) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.