-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Implement StringArray.min / max #33351
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 11 commits
a470f02
a50a2c4
4e09c50
6e8f0c5
34f8d5f
08ce4d5
fa13cec
64e6d19
d804e4b
5cc91e0
0c98b08
df6ba29
3613f65
fd62963
9083273
208835c
77144d0
9197125
3fcd200
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 |
---|---|---|
|
@@ -230,6 +230,26 @@ def test_reduce(skipna): | |
assert result == "abc" | ||
|
||
|
||
@pytest.mark.parametrize("method", ["min", "max"]) | ||
@pytest.mark.parametrize("skipna", [True, False]) | ||
def test_min_max(method, skipna): | ||
arr = pd.Series(["a", "b", "c", None], dtype="string") | ||
result = getattr(arr, method)(skipna=skipna) | ||
if skipna: | ||
expected = "a" if method == "min" else "c" | ||
assert result == expected | ||
else: | ||
assert result is pd.NA | ||
|
||
|
||
@pytest.mark.parametrize("method", ["min", "max"]) | ||
def test_min_max_numpy(method): | ||
arr = pd.Series(["a", "b", "c", None], dtype="string") | ||
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. so we should also test here for the actual array (and not put in a Series), maybe parametrize over pd.array and pd.Series as constructor |
||
result = getattr(np, method)(arr) | ||
expected = "a" if method == "min" else "c" | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert result == expected | ||
|
||
|
||
@pytest.mark.parametrize("skipna", [True, False]) | ||
@pytest.mark.xfail(reason="Not implemented StringArray.sum") | ||
def test_reduce_missing(skipna): | ||
|
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 [ | ||
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. hmm, @TomAugspurger, @jbrockmendel is this the pattern we are using here for skips like 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. in indexes tests when we have a "this is tested in this other place" comment we usually return/pass instead of pytest.skip. It's not a perfect system, but I think of it as a way of distinguishing between "this test is skipped but would be nice to enable" vs "nothing to see here" 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. Returning None rather than skipping also keeps the test output cleaner, since we print skipped tests. 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. We typically refine this for a specific type by overriding this test to have custom behaviour in 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. ok on the test names? @jorisvandenbossche 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. @dsaxton can you move this special case for string to |
||
"min", | ||
"max", | ||
]: | ||
# Tested in pandas/tests/arrays/string_/test_string.py | ||
return None | ||
|
||
op_name = all_numeric_reductions | ||
s = pd.Series(data) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.