Skip to content

Commit d740f43

Browse files
committed
don't create a separate method
1 parent 5d9d2c2 commit d740f43

File tree

2 files changed

+8
-40
lines changed

2 files changed

+8
-40
lines changed

pandas/core/dtypes/common.py

-38
Original file line numberDiff line numberDiff line change
@@ -1231,44 +1231,6 @@ def needs_i8_conversion(arr_or_dtype) -> bool:
12311231
)
12321232

12331233

1234-
def np_issubclass_compat(unique_dtype, dtypes_set) -> bool:
1235-
"""
1236-
Check whether the provided dtype is a subclass of, or has an attribute
1237-
(e.g. _is_numeric) indiciating it is a subclass of any of the dtypes in
1238-
dtypes_set.
1239-
1240-
Parameters
1241-
----------
1242-
unique_dtype : dtype
1243-
The dtype to check.
1244-
dtypes_set : array-like
1245-
The dtypes to check unique_dtype is a sublass of.
1246-
1247-
Returns
1248-
-------
1249-
boolean
1250-
Whether or not the unique_dtype is a subclass of dtype_set.
1251-
1252-
Examples
1253-
--------
1254-
>>> np_issubclass_compat(pd.Int16Dtype(), [np.bool_, np.float])
1255-
False
1256-
>>> np_issubclass_compat(pd.Int16Dtype(), [np.integer])
1257-
True
1258-
>>> np_issubclass_compat(pd.BooleanDtype(), [np.bool_])
1259-
True
1260-
>>> np_issubclass_compat(pd.Float64Dtype(), [np.float])
1261-
True
1262-
>>> np_issubclass_compat(pd.Float64Dtype(), [np.number])
1263-
True
1264-
"""
1265-
return issubclass(unique_dtype.type, tuple(dtypes_set)) or (
1266-
np.number in dtypes_set
1267-
and hasattr(unique_dtype, "_is_numeric") # is an extensionarray
1268-
and unique_dtype._is_numeric
1269-
)
1270-
1271-
12721234
def is_numeric_dtype(arr_or_dtype) -> bool:
12731235
"""
12741236
Check whether the provided array or dtype is of a numeric dtype.

pandas/core/frame.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@
114114
is_object_dtype,
115115
is_scalar,
116116
is_sequence,
117-
np_issubclass_compat,
118117
pandas_dtype,
119118
)
120119
from pandas.core.dtypes.missing import isna, notna
@@ -3713,7 +3712,14 @@ def extract_unique_dtypes_from_dtypes_set(
37133712
extracted_dtypes = [
37143713
unique_dtype
37153714
for unique_dtype in unique_dtypes
3716-
if np_issubclass_compat(unique_dtype, dtypes_set)
3715+
if (
3716+
issubclass(unique_dtype.type, tuple(dtypes_set))
3717+
or (
3718+
np.number in dtypes_set
3719+
and hasattr(unique_dtype, "_is_numeric")
3720+
and unique_dtype._is_numeric
3721+
)
3722+
)
37173723
]
37183724
return extracted_dtypes
37193725

0 commit comments

Comments
 (0)