Skip to content

Commit 78740c7

Browse files
committed
various fixups
1 parent 61e859e commit 78740c7

File tree

5 files changed

+10
-13
lines changed

5 files changed

+10
-13
lines changed

pandas/core/array_algos/masked_reductions.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ def _minmax(
122122
return func(values, axis=axis)
123123
else:
124124
subset = values[~mask]
125-
if not subset.size:
125+
if subset.size:
126+
return func(values, where=~mask, axis=axis, initial=subset[0])
126127
# min/max with empty array raise in numpy, pandas returns NA
128+
else:
127129
return libmissing.NA
128-
return func(values, where=~mask, axis=axis, initial=subset[0])
129130

130131

131132
def min(

pandas/core/arrays/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ def _reduce(self, name: str, *, skipna: bool = True, **kwargs):
14311431
See Also
14321432
--------
14331433
ExtensionArray._reduce_with_wrap
1434-
Calls ``_reduce`` and wraps the result in a ndarray/extensionArray.
1434+
Calls ``_reduce`` and wraps the result in a ndarray/ExtensionArray.
14351435
"""
14361436
meth = getattr(self, name, None)
14371437
if meth is None:

pandas/core/frame.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -11174,10 +11174,9 @@ def idxmin(
1117411174
)
1117511175
indices = res._values
1117611176

11177-
# indices will always be np.ndarray since axis is not None and
11177+
# indices will always be 1d array since axis is not None and
1117811178
# values is a 2d array for DataFrame
11179-
# error: Item "int" of "Union[int, Any]" has no attribute "__iter__"
11180-
assert isinstance(indices, (np.ndarray, ExtensionArray)) # for mypy
11179+
# indices will always be np.ndarray since axis is not N
1118111180

1118211181
index = data._get_axis(axis)
1118311182
result = [index[i] if i >= 0 else np.nan for i in indices]
@@ -11199,9 +11198,8 @@ def idxmax(
1119911198
)
1120011199
indices = res._values
1120111200

11202-
# indices will always be np.ndarray since axis is not None and
11201+
# indices will always be 1d array since axis is not None and
1120311202
# values is a 2d array for DataFrame
11204-
# error: Item "int" of "Union[int, Any]" has no attribute "__iter__"
1120511203
assert isinstance(indices, (np.ndarray, ExtensionArray)) # for mypy
1120611204

1120711205
index = data._get_axis(axis)

pandas/core/internals/blocks.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,9 @@ def reduce(self, func) -> list[Block]:
340340

341341
if self.values.ndim == 1:
342342
# TODO(EA2D): special case not needed with 2D EAs
343-
if isinstance(result, (np.ndarray, ExtensionArray)):
344-
res_values = result
345-
else:
346-
res_values = np.array([[result]])
343+
if not isinstance(result, (np.ndarray, ExtensionArray)):
344+
result = np.array([[result]])
345+
res_values = result
347346
else:
348347
res_values = result.reshape(-1, 1)
349348

pandas/tests/extension/test_arrow.py

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
from pandas.core.arrays.arrow.dtype import ArrowDtype # isort:skip
6363

6464

65-
6665
@pytest.fixture(params=tm.ALL_PYARROW_DTYPES, ids=str)
6766
def dtype(request):
6867
return ArrowDtype(pyarrow_dtype=request.param)

0 commit comments

Comments
 (0)