Skip to content

Commit

Permalink
BUG: is_bool_dtype raises AttributeError when checking categorical Se…
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbie-Palmer authored and phofl committed Feb 14, 2022
1 parent 3f7344e commit 13abfb4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.4.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Bug fixes
- Fixed segfault in :meth:``DataFrame.to_json`` when dumping tz-aware datetimes in Python 3.10 (:issue:`42130`)
- Stopped emitting unnecessary ``FutureWarning`` in :meth:`DataFrame.sort_values` with sparse columns (:issue:`45618`)
- Fixed window aggregations in :meth:`DataFrame.rolling` and :meth:`Series.rolling` to skip over unused elements (:issue:`45647`)
-
- Bug in :func:`api.types.is_bool_dtype` was raising an ``AttributeError`` when evaluating a categorical :class:`Series` (:issue:`45615`)

.. ---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ def is_bool_dtype(arr_or_dtype) -> bool:
return False

if isinstance(dtype, CategoricalDtype):
arr_or_dtype = arr_or_dtype.categories
arr_or_dtype = dtype.categories
# now we use the special definition for Index

if isinstance(arr_or_dtype, ABCIndex):
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/dtypes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,14 @@ def test_is_bool_dtype():
assert not com.is_bool_dtype(int)
assert not com.is_bool_dtype(str)
assert not com.is_bool_dtype(pd.Series([1, 2]))
assert not com.is_bool_dtype(pd.Series(["a", "b"], dtype="category"))
assert not com.is_bool_dtype(np.array(["a", "b"]))
assert not com.is_bool_dtype(pd.Index(["a", "b"]))
assert not com.is_bool_dtype("Int64")

assert com.is_bool_dtype(bool)
assert com.is_bool_dtype(np.bool_)
assert com.is_bool_dtype(pd.Series([True, False], dtype="category"))
assert com.is_bool_dtype(np.array([True, False]))
assert com.is_bool_dtype(pd.Index([True, False]))

Expand Down

0 comments on commit 13abfb4

Please sign in to comment.