Skip to content

Commit be68850

Browse files
PERF: special case numpy.dtype in is_extension_array_dtype (#39678)
1 parent ab82fb0 commit be68850

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

asv_bench/benchmarks/dtypes.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import numpy as np
44

5+
import pandas as pd
56
from pandas import DataFrame
67
import pandas._testing as tm
7-
from pandas.api.types import pandas_dtype
8+
from pandas.api.types import is_extension_array_dtype, pandas_dtype
89

910
from .pandas_vb_common import (
1011
datetime_dtypes,
@@ -119,4 +120,16 @@ def time_select_dtype_string_exclude(self, dtype):
119120
self.df_string.select_dtypes(exclude=dtype)
120121

121122

123+
class CheckDtypes:
124+
def setup(self):
125+
self.ext_dtype = pd.Int64Dtype()
126+
self.np_dtype = np.dtype("int64")
127+
128+
def time_is_extension_array_dtype_true(self):
129+
is_extension_array_dtype(self.ext_dtype)
130+
131+
def time_is_extension_array_dtype_false(self):
132+
is_extension_array_dtype(self.np_dtype)
133+
134+
122135
from .pandas_vb_common import setup # noqa: F401 isort:skip

pandas/core/dtypes/common.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,12 @@ def is_extension_array_dtype(arr_or_dtype) -> bool:
15261526
False
15271527
"""
15281528
dtype = getattr(arr_or_dtype, "dtype", arr_or_dtype)
1529-
return isinstance(dtype, ExtensionDtype) or registry.find(dtype) is not None
1529+
if isinstance(dtype, ExtensionDtype):
1530+
return True
1531+
elif isinstance(dtype, np.dtype):
1532+
return False
1533+
else:
1534+
return registry.find(dtype) is not None
15301535

15311536

15321537
def is_ea_or_datetimelike_dtype(dtype: Optional[DtypeObj]) -> bool:

0 commit comments

Comments
 (0)