Skip to content

BUG: mapping categorical with single category to boolean returns category instead of bool dtype #61719

Open
@kdebrab

Description

@kdebrab

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

pd.Series(["a", "a"]).astype("category").map(lambda x: x == "c")

Issue Description

The above snippet erroneously returns category dtype:

0    False
1    False
dtype: category
Categories (1, bool): [False]

Expected Behavior

As soon as there are at least two categories, one gets the expected bool dtype:

pd.Series(["a", "b"]).astype("category").map(lambda x: x == "c")

returns:

0    False
1    False
dtype: bool

I would expect the same result if there is only one category involved.

Installed Versions

INSTALLED VERSIONS

commit : 2cc3762
python : 3.12.9
python-bits : 64
OS : Windows
OS-release : 11
Version : 10.0.26100
machine : AMD64
processor : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_Belgium.1252
pandas : 2.3.0
numpy : 2.3.1
pytz : 2025.2
dateutil : 2.9.0.post0
pip : None
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : 1.5.0
dataframe-api-compat : None
fastparquet : None
fsspec : 2025.5.1
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : 5.4.0
matplotlib : 3.10.3
numba : None
numexpr : 2.11.0
odfpy : None
openpyxl : 3.1.5
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 20.0.0
pyreadstat : None
pytest : 8.4.1
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.15.3
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : 2025.3.1
xlrd : None
xlsxwriter : 3.2.5
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

Labels

ApplyApply, Aggregate, Transform, MapBugCategoricalCategorical Data Type

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions