Skip to content

Commit a17e0c5

Browse files
Robbie-Palmeryehoshuadimarsky
authored andcommitted
BUG: is_bool_dtype raises AttributeError when checking categorical Series (pandas-dev#45616)
1 parent 469e582 commit a17e0c5

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

doc/source/whatsnew/v1.4.1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Bug fixes
3131
- Fixed segfault in :meth:``DataFrame.to_json`` when dumping tz-aware datetimes in Python 3.10 (:issue:`42130`)
3232
- Stopped emitting unnecessary ``FutureWarning`` in :meth:`DataFrame.sort_values` with sparse columns (:issue:`45618`)
3333
- Fixed window aggregations in :meth:`DataFrame.rolling` and :meth:`Series.rolling` to skip over unused elements (:issue:`45647`)
34-
-
34+
- Bug in :func:`api.types.is_bool_dtype` was raising an ``AttributeError`` when evaluating a categorical :class:`Series` (:issue:`45615`)
3535

3636
.. ---------------------------------------------------------------------------
3737

pandas/core/dtypes/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ def is_bool_dtype(arr_or_dtype) -> bool:
13191319
return False
13201320

13211321
if isinstance(dtype, CategoricalDtype):
1322-
arr_or_dtype = arr_or_dtype.categories
1322+
arr_or_dtype = dtype.categories
13231323
# now we use the special definition for Index
13241324

13251325
if isinstance(arr_or_dtype, ABCIndex):

pandas/tests/dtypes/test_common.py

+2
Original file line numberDiff line numberDiff line change
@@ -562,12 +562,14 @@ def test_is_bool_dtype():
562562
assert not com.is_bool_dtype(int)
563563
assert not com.is_bool_dtype(str)
564564
assert not com.is_bool_dtype(pd.Series([1, 2]))
565+
assert not com.is_bool_dtype(pd.Series(["a", "b"], dtype="category"))
565566
assert not com.is_bool_dtype(np.array(["a", "b"]))
566567
assert not com.is_bool_dtype(pd.Index(["a", "b"]))
567568
assert not com.is_bool_dtype("Int64")
568569

569570
assert com.is_bool_dtype(bool)
570571
assert com.is_bool_dtype(np.bool_)
572+
assert com.is_bool_dtype(pd.Series([True, False], dtype="category"))
571573
assert com.is_bool_dtype(np.array([True, False]))
572574
assert com.is_bool_dtype(pd.Index([True, False]))
573575

0 commit comments

Comments
 (0)