Skip to content

Commit 754d091

Browse files
authoredNov 8, 2024··
BUG (string dtype): correctly enable idxmin/max for python-storage strings (#60242)
1 parent db38017 commit 754d091

File tree

3 files changed

+1
-14
lines changed

3 files changed

+1
-14
lines changed
 

‎pandas/core/arrays/string_.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ def _reduce(
846846
else:
847847
return nanops.nanall(self._ndarray, skipna=skipna)
848848

849-
if name in ["min", "max", "sum"]:
849+
if name in ["min", "max", "argmin", "argmax", "sum"]:
850850
result = getattr(self, name)(skipna=skipna, axis=axis, **kwargs)
851851
if keepdims:
852852
return self._from_sequence([result], dtype=self.dtype)

‎pandas/tests/frame/test_reductions.py

-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import numpy as np
77
import pytest
88

9-
from pandas._config import using_string_dtype
10-
119
from pandas.compat import (
1210
IS64,
1311
is_platform_windows,
@@ -1081,7 +1079,6 @@ def test_idxmin_empty(self, index, skipna, axis):
10811079
expected = Series(dtype=index.dtype)
10821080
tm.assert_series_equal(result, expected)
10831081

1084-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
10851082
@pytest.mark.parametrize("numeric_only", [True, False])
10861083
def test_idxmin_numeric_only(self, numeric_only):
10871084
df = DataFrame({"a": [2, 3, 1], "b": [2, 1, 1], "c": list("xyx")})
@@ -1098,7 +1095,6 @@ def test_idxmin_axis_2(self, float_frame):
10981095
with pytest.raises(ValueError, match=msg):
10991096
frame.idxmin(axis=2)
11001097

1101-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
11021098
@pytest.mark.parametrize("axis", [0, 1])
11031099
def test_idxmax(self, float_frame, int_frame, skipna, axis):
11041100
frame = float_frame
@@ -1132,7 +1128,6 @@ def test_idxmax_empty(self, index, skipna, axis):
11321128
expected = Series(dtype=index.dtype)
11331129
tm.assert_series_equal(result, expected)
11341130

1135-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
11361131
@pytest.mark.parametrize("numeric_only", [True, False])
11371132
def test_idxmax_numeric_only(self, numeric_only):
11381133
df = DataFrame({"a": [2, 3, 1], "b": [2, 1, 1], "c": list("xyx")})

‎pandas/tests/reductions/test_reductions.py

-8
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
import numpy as np
88
import pytest
99

10-
from pandas._config import using_string_dtype
11-
12-
from pandas.compat import HAS_PYARROW
13-
1410
import pandas as pd
1511
from pandas import (
1612
Categorical,
@@ -1206,10 +1202,6 @@ def test_idxminmax_object_dtype(self, using_infer_string):
12061202
with pytest.raises(TypeError, match=msg):
12071203
ser3.idxmin(skipna=False)
12081204

1209-
# TODO(infer_string) implement argmin/max for python string dtype
1210-
@pytest.mark.xfail(
1211-
using_string_dtype() and not HAS_PYARROW, reason="TODO(infer_string)"
1212-
)
12131205
def test_idxminmax_object_frame(self):
12141206
# GH#4279
12151207
df = DataFrame([["zimm", 2.5], ["biff", 1.0], ["bid", 12.0]])

0 commit comments

Comments
 (0)
Please sign in to comment.