-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Implement some reductions for string Series #31757
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 8 commits
c87ce47
5365fa1
460030f
6497e16
c052feb
4312b4f
b67cc56
214995f
95c83fb
4082ae3
12a2323
4a61b81
c6465e5
5c1a5fb
ca99650
18800e1
3eddb73
0c1a2a3
5714c06
5e01c3f
0e4a4e2
ed01138
1128950
7c0f05d
d84f5bd
7db2052
e19bbe1
df99b4f
ba20705
d69b587
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 |
|---|---|---|
|
|
@@ -274,7 +274,16 @@ def astype(self, dtype, copy=True): | |
| return super().astype(dtype, copy) | ||
|
|
||
| def _reduce(self, name, skipna=True, **kwargs): | ||
| raise TypeError(f"Cannot perform reduction '{name}' with string dtype") | ||
| if name in ["min", "max", "sum"]: | ||
| na_mask = isna(self) | ||
|
||
| if not na_mask.any(): | ||
| return getattr(self, name)(skipna=False, **kwargs) | ||
| elif skipna: | ||
| return getattr(self[~na_mask], name)(skipna=False, **kwargs) | ||
| else: | ||
| return libmissing.NA | ||
| else: | ||
dsaxton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| raise TypeError(f"Cannot perform reduction '{name}' with string dtype") | ||
|
|
||
| def value_counts(self, dropna=False): | ||
| from pandas import value_counts | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,13 @@ class BaseNoReduceTests(BaseReduceTests): | |
|
|
||
| @pytest.mark.parametrize("skipna", [True, False]) | ||
| def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna): | ||
| if isinstance(data, pd.arrays.StringArray) and all_numeric_reductions in [ | ||
| "min", | ||
| "max", | ||
| "sum", | ||
| ]: | ||
| pytest.skip("These reductions are implemented") | ||
|
||
|
|
||
| op_name = all_numeric_reductions | ||
| s = pd.Series(data) | ||
|
|
||
|
|
||
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.
this is likely too invasive for 1.02, move to 1.1