Skip to content

Commit bd7b06b

Browse files
committed
ENH: Unbox NumPy scalars in indexing
1 parent 7bf6660 commit bd7b06b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

pandas/core/indexes/base.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
common_dtype_categorical_compat,
9393
find_result_type,
9494
infer_dtype_from,
95+
maybe_unbox_numpy_scalar,
9596
np_can_hold_element,
9697
)
9798
from pandas.core.dtypes.common import (
@@ -7534,7 +7535,7 @@ def min(self, axis: AxisInt | None = None, skipna: bool = True, *args, **kwargs)
75347535
# quick check
75357536
first = self[0]
75367537
if not isna(first):
7537-
return first
7538+
return maybe_unbox_numpy_scalar(first)
75387539

75397540
if not self._is_multi and self.hasnans:
75407541
# Take advantage of cache
@@ -7545,7 +7546,7 @@ def min(self, axis: AxisInt | None = None, skipna: bool = True, *args, **kwargs)
75457546
if not self._is_multi and not isinstance(self._values, np.ndarray):
75467547
return self._values._reduce(name="min", skipna=skipna)
75477548

7548-
return nanops.nanmin(self._values, skipna=skipna)
7549+
return maybe_unbox_numpy_scalar(nanops.nanmin(self._values, skipna=skipna))
75497550

75507551
def max(self, axis: AxisInt | None = None, skipna: bool = True, *args, **kwargs):
75517552
"""
@@ -7598,18 +7599,18 @@ def max(self, axis: AxisInt | None = None, skipna: bool = True, *args, **kwargs)
75987599
# quick check
75997600
last = self[-1]
76007601
if not isna(last):
7601-
return last
7602+
return maybe_unbox_numpy_scalar(last)
76027603

76037604
if not self._is_multi and self.hasnans:
76047605
# Take advantage of cache
76057606
mask = self._isnan
76067607
if not skipna or mask.all():
7607-
return self._na_value
7608+
return maybe_unbox_numpy_scalar(self._na_value)
76087609

76097610
if not self._is_multi and not isinstance(self._values, np.ndarray):
76107611
return self._values._reduce(name="max", skipna=skipna)
76117612

7612-
return nanops.nanmax(self._values, skipna=skipna)
7613+
return maybe_unbox_numpy_scalar(nanops.nanmax(self._values, skipna=skipna))
76137614

76147615
# --------------------------------------------------------------------
76157616

0 commit comments

Comments
 (0)