Skip to content

BUG: Partial support only for extension DTypes in pandas.core.dtypes.common #45417

Closed
@erezinman

Description

@erezinman

Pandas version checks

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

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
import pandas.core.dtypes.common as pdc

pdc.is_bool_dtype(pd.BooleanDtype)

Issue Description

The above code returns a property and not bool.
The bug here is actually because of pandas.core.dtypes.common.get_dtype that doesn't deal with extension DTypes (I guess it should return the extension DType, but I'm unsure). On the other hand, if the get_dtype method should not work with extension DTypes (for some reason), then it should check if this in an extension DType prior to calling get_dtype.

Anyway, is_bool_dtype should return a boolean and it doesn't necessarily do so (and I'm sure that it's a problem with many other functions in this module).

This is also the issue with not inferring strings that represent extension DTypes. Calling

pdc.is_bool_dtype('boolean')

yields

AttributeError: 'str' object has no attribute '_is_boolean'

Thanks

p.s. Regarding checking the bug's existence, I encountered it in my python v.3.6.9 code (so it can't be updated to the latest), but I checked the code in the repo, and I'm quite sure that it should reproduce.

Expected Behavior

  1. get_dtype(ExtensionDtype) should return that DType.
  2. is_bool_dtype and similar should always return boolean values.
  3. is_bool_dtype('boolean') should not raise an exception.
  4. is_bool_dtype(pd.BooleanDtype) should return True (like pdc.is_bool_dtype(pd.Series([], dtype='boolean')) does)

Installed Versions

INSTALLED VERSIONS

commit : 2a7d332
python : 3.6.9.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-77-generic
Version : #86~18.04.1-Ubuntu SMP Fri Jun 18 01:23:22 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.2
numpy : 1.19.5
pytz : 2018.3
dateutil : 2.8.1
pip : 21.1.3
setuptools : 45.2.0
Cython : 0.29.21
pytest : 5.3.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.0
html5lib : 0.999999999
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.16.1
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : 0.8.7
fastparquet : 0.4.1
gcsfs : None
matplotlib : 3.3.4
numexpr : 2.7.2
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : 4.0.1
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.4.17
tables : 3.6.1
tabulate : 0.8.7
xarray : 0.16.0
xlrd : 1.2.0
xlwt : None
numba : 0.48.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugExtensionArrayExtending 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