Skip to content

BUG: pd.core.dtypes.common.is_extension_array_dtype wrong output for some dtypes #40478

Closed
@siboehm

Description

@siboehm
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

from pandas.core.dtypes.common import is_extension_array_dtype
from pandas.core.base import ExtensionArray

dt = DatetimeArray(np.array([], dtype='datetime64[ns]'))
assert isinstance(dt, ExtensionArray) # passes
assert is_extension_array_dtype(dt) # fails
assert is_extension_array_dtype(dt.dtype) # fails

inter = pd.Interval(0, 5)
assert com.is_extension_array_dtype(inter) # fails

Similar problems for Period and timedelta64[ns].

Problem description

Some of it (example: DatetimeArray) is due to this commit: be68850#diff-e279f0dcc8af317412f2a0db83d50c2ffedcd0743af7da8545ff272ee6ebe2f3R1529

Where DatetimeArray implements ExtensionArray, but datetime64[ns] is a np dtype and doesn't (yet) implement ExtensionDtype.

Expected Output

Function should return true for all dtypes whose Array implements ExtensionArray.

I need this for #40450.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : a75152784c17a73627a414319f6c89324cfa2840
python : 3.8.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.8.0-44-generic
Version : #50-Ubuntu SMP Tue Feb 9 06:29:41 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : C.UTF-8
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.0.dev0+1084.ga75152784c.dirty
numpy : 1.19.5
pytz : 2021.1
dateutil : 2.8.1
pip : 20.3.3
setuptools : 49.6.0.post20201009
Cython : 0.29.22
pytest : 6.2.2
hypothesis : 6.7.0
sphinx : 3.5.2
blosc : None
feather : None
xlsxwriter : 1.3.7
lxml.etree : 4.6.2
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.21.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : 1.3.2
fsspec : 0.8.7
fastparquet : 0.5.0
gcsfs : 0.7.2
matplotlib : 3.3.4
numexpr : 2.7.3
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : 3.0.0
pyxlsb : None
s3fs : 0.4.2
scipy : 1.6.0
sqlalchemy : 1.3.23
tables : 3.6.1
tabulate : 0.8.9
xarray : 0.17.0
xlrd : 2.0.1
xlwt : 1.3.0
numba : 0.52.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Dtype ConversionsUnexpected or buggy dtype conversionsExtensionArrayExtending pandas with custom dtypes or arrays.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions