Skip to content

BUG: is_bool_dtype 'Series' object has no attribute 'categories' #45615

Closed
@Robbie-Palmer

Description

@Robbie-Palmer

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

from pandas import Series
from pandas.core.dtypes.common import is_bool_dtype

s = Series(['foo', 'bar', 'baz'], dtype='category')
is_bool_dtype(s)

Issue Description

In pandas v1.3.0 the is_bool_dtype function returns False when passed a categorical Series
In pandas v1.4.0 it raises the error :

Traceback (most recent call last):
  File "./pandas/core/dtypes/common.py", line 1322, in is_bool_dtype
    arr_or_dtype = arr_or_dtype.categories
  File "./pandas/core/generic.py", line 5583, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'categories'

Expected Behavior

Expect is_bool_dtype to return False for categorical Series as happened in previous pandas versions

Installed Versions

INSTALLED VERSIONS

commit : bb1f651
python : 3.9.7.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-96-generic
Version : #109-Ubuntu SMP Wed Jan 12 16:49:16 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.4.0
numpy : 1.21.3
pytz : 2021.3
dateutil : 2.8.2
pip : 20.2.4
setuptools : 59.6.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.3.7
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.5
pandas_gbq : None
pyarrow : 5.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None

Metadata

Metadata

Assignees

Labels

BugDtype ConversionsUnexpected or buggy dtype conversionsRegressionFunctionality that used to work in a prior pandas version

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions