Skip to content

Commit 2c89984

Browse files
[backport 2.3.x] BUG (string dtype): correctly enable idxmin/max for python-storage strings (#60242) (#60256)
BUG (string dtype): correctly enable idxmin/max for python-storage strings (#60242) (cherry picked from commit 754d091)
1 parent 4527585 commit 2c89984

File tree

3 files changed

+1
-15
lines changed

3 files changed

+1
-15
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

-6
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,
@@ -1091,7 +1089,6 @@ def test_idxmin_empty(self, index, skipna, axis):
10911089
expected = Series(dtype=index.dtype)
10921090
tm.assert_series_equal(result, expected)
10931091

1094-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
10951092
@pytest.mark.parametrize("numeric_only", [True, False])
10961093
def test_idxmin_numeric_only(self, numeric_only):
10971094
df = DataFrame({"a": [2, 3, 1], "b": [2, 1, 1], "c": list("xyx")})
@@ -1108,8 +1105,6 @@ def test_idxmin_axis_2(self, float_frame):
11081105
with pytest.raises(ValueError, match=msg):
11091106
frame.idxmin(axis=2)
11101107

1111-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
1112-
@pytest.mark.parametrize("skipna", [True, False])
11131108
@pytest.mark.parametrize("axis", [0, 1])
11141109
def test_idxmax(self, float_frame, int_frame, skipna, axis):
11151110
frame = float_frame
@@ -1142,7 +1137,6 @@ def test_idxmax_empty(self, index, skipna, axis):
11421137
expected = Series(dtype=index.dtype)
11431138
tm.assert_series_equal(result, expected)
11441139

1145-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
11461140
@pytest.mark.parametrize("numeric_only", [True, False])
11471141
def test_idxmax_numeric_only(self, numeric_only):
11481142
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,
@@ -1246,10 +1242,6 @@ def test_idxminmax_object_dtype(self, using_infer_string):
12461242
with pytest.raises(TypeError, match=msg):
12471243
ser3.idxmin(skipna=False)
12481244

1249-
# TODO(infer_string) implement argmin/max for python string dtype
1250-
@pytest.mark.xfail(
1251-
using_string_dtype() and not HAS_PYARROW, reason="TODO(infer_string)"
1252-
)
12531245
def test_idxminmax_object_frame(self):
12541246
# GH#4279
12551247
df = DataFrame([["zimm", 2.5], ["biff", 1.0], ["bid", 12.0]])

0 commit comments

Comments
 (0)