Skip to content

Commit 6f5287b

Browse files
authored
CLN: avoid values_from_object in nanops (#32508)
1 parent 19ae087 commit 6f5287b

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

pandas/core/nanops.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
)
3333
from pandas.core.dtypes.missing import isna, na_value_for_dtype, notna
3434

35+
from pandas.core.construction import extract_array
36+
3537
bn = import_optional_dependency("bottleneck", raise_on_missing=False, on_version="warn")
3638
_BOTTLENECK_INSTALLED = bn is not None
3739
_USE_BOTTLENECK = False
@@ -284,14 +286,8 @@ def _get_values(
284286

285287
mask = _maybe_get_mask(values, skipna, mask)
286288

287-
if is_datetime64tz_dtype(values):
288-
# lib.values_from_object returns M8[ns] dtype instead of tz-aware,
289-
# so this case must be handled separately from the rest
290-
dtype = values.dtype
291-
values = getattr(values, "_values", values)
292-
else:
293-
values = lib.values_from_object(values)
294-
dtype = values.dtype
289+
values = extract_array(values, extract_numpy=True)
290+
dtype = values.dtype
295291

296292
if is_datetime_or_timedelta_dtype(values) or is_datetime64tz_dtype(values):
297293
# changing timedelta64/datetime64 to int64 needs to happen after
@@ -758,7 +754,7 @@ def nanvar(values, axis=None, skipna=True, ddof=1, mask=None):
758754
>>> nanops.nanvar(s)
759755
1.0
760756
"""
761-
values = lib.values_from_object(values)
757+
values = extract_array(values, extract_numpy=True)
762758
dtype = values.dtype
763759
mask = _maybe_get_mask(values, skipna, mask)
764760
if is_any_int_dtype(values):
@@ -985,7 +981,7 @@ def nanskew(
985981
>>> nanops.nanskew(s)
986982
1.7320508075688787
987983
"""
988-
values = lib.values_from_object(values)
984+
values = extract_array(values, extract_numpy=True)
989985
mask = _maybe_get_mask(values, skipna, mask)
990986
if not is_float_dtype(values.dtype):
991987
values = values.astype("f8")
@@ -1069,7 +1065,7 @@ def nankurt(
10691065
>>> nanops.nankurt(s)
10701066
-1.2892561983471076
10711067
"""
1072-
values = lib.values_from_object(values)
1068+
values = extract_array(values, extract_numpy=True)
10731069
mask = _maybe_get_mask(values, skipna, mask)
10741070
if not is_float_dtype(values.dtype):
10751071
values = values.astype("f8")

0 commit comments

Comments
 (0)