BUG: to_hdf fails with boolean index in 1.5

This issue has been created since 2022-09-20.

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.DataFrame([[False, 1]], columns=["a", "b"]).set_index(['a']).to_hdf("/tmp/a.hdf", "a")

Issue Description

When saving to_hdf a dataframe which has a boolean index I get an assertion error from inside pytables

   4943     return IndexCol(
   4944         name, values=converted, kind=kind, typ=atom, index_name=index_name
   4945     )
   4946 else:
-> 4947     assert isinstance(converted, np.ndarray) and converted.dtype == object
   4948     assert kind == "object", kind
   4949     atom = _tables().ObjectAtom()

AssertionError:

However, when saving a dataframe with no boolean in the index this works as expected.

Additionally saving dataframes with booleans in the index worked in 1.4.4

Expected Behavior

import pandas as pd
pd.DataFrame([[False, 1]], columns=["a", "b"]).set_index(['a']).to_hdf("/tmp/a.hdf", "a")

works identically to

import pandas as pd
pd.DataFrame([['False', 1]], columns=["a", "b"]).set_index(['a']).to_hdf("/tmp/a.hdf", "a")

Installed Versions

INSTALLED VERSIONS

commit : 87cfe4e
python : 3.10.7.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.117.hrtdev
Version : #3 SMP Tue May 11 13:44:03 EDT 2021
machine : x86_64
processor :
byteorder : little
LC_ALL :
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.0
numpy : 1.23.2
pytz : 2022.1
dateutil : 2.8.2
setuptools : 62.1.0
pip : 22.2.2
Cython : 0.29.30
pytest : 7.1.2
hypothesis : 6.52.3
sphinx : 5.0.2
blosc : 1.10.6
feather : None
xlsxwriter : None
lxml.etree : 4.9.1
html5lib : 1.1
pymysql : 1.0.2
psycopg2 : 2.9.3
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : 1.3.5
brotli : 1.0.9
fastparquet : 0.8.1
fsspec : 2022.5.0
gcsfs : None
matplotlib : 3.5.2
numba : 0.56.2
numexpr : 2.8.3
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : 7.0.0
pyreadstat : None
pyxlsb : 1.0.9
s3fs : None
scipy : 1.9.1
snappy : None
sqlalchemy : 1.4.39
tables : 3.7.0
tabulate : 0.8.10
xarray : 2022.6.0
xlrd : 2.0.1
xlwt : None
zstandard : 0.18.0
tzdata : 2022.1

anthonyaag wrote this answer on 2022-09-21

Seems to be a change from the dtype of the index

1.5 behavior
In [12]: pd.DataFrame([[True, 1]], columns=["a", "b"]).set_index("a").index
Out[12]: Index([True], dtype='bool', name='a')

1.4 behavior
In [11]: pd.DataFrame([[True, 1]], columns=["a", "b"]).set_index("a").index
Out[11]: Index([True], dtype='object', name='a')

phofl wrote this answer on 2022-09-21
ee6b0a09fff7789879c3322edffe9f84d10acee3 is the first bad commit
commit ee6b0a09fff7789879c3322edffe9f84d10acee3
Author: jbrockmendel <[email protected]>
Date:   Sat Feb 5 11:01:21 2022 -0800

    ENH: Index[bool] (#45061)
More Details About Repo
Owner Name pandas-dev
Repo Name pandas
Full Name pandas-dev/pandas
Language Python
Created Date 2010-08-24
Updated Date 2022-09-29
Star Count 35373
Watcher Count 1123
Fork Count 15031
Issue Count 3581

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
[Feature][Config UI] Discussion for Blueprint Editing and Deletion 1 2022-07-12 2022-09-19
Bump alecthomas/chroma 4 2021-10-16 2022-09-22
Adjust border of options container 0 2022-03-16 2022-07-02
[Bug]: `Pack.cmd` Fails 0 2021-11-25 2022-07-31
M115 code unsupported 0 2021-06-25 2022-09-16
Report resource utilization 2 2021-10-22 2022-08-14
Not setting a default value for shutter_speed causing video to be too dark 0 2021-01-22 2022-07-17
Bug in UAIReader 0 2021-07-27 2022-01-15
Browser shows directory listing instead of normal gui 2 2021-03-10 2022-09-18
Sanitizing markdown input 5 2018-10-11 2022-08-03
Using without Steam & Unity 2 2021-06-12 2022-09-18
Performance issues when loading some .tif files 7 2021-04-06 2022-09-25
Browser default font applied in text 2 2021-12-13 2022-09-03
Jumper t-Pro Boot Screen Contrast very low 2 2022-03-14 2022-09-21
OC settings RX 6600 XT 2 2021-11-12 2022-09-10
Where are releases published? 2 2021-07-29 2022-09-23
node_modules/swagger-jsdoc/src/specification.js:141 for (const definition of Object.keys(annotation[property])) Cannot convert undefined or null to object 1 2021-12-13 2022-09-16
values must be atoms or strings 3 2019-11-28 2022-09-26
XSS Stored 0 2022-01-13 2022-01-14
parse_datetime crashes R session when providing invalid format specification 1 2021-03-01 2022-09-11
Styling for some non-image placeholders is broken after the CSS aspect-ratio was removed 1 2021-02-03 2022-08-31
Don't record motion when camera is in Home security mode 5 2021-11-29 2022-07-17
Omitting system-wide ssh configuration 3 2020-10-19 2022-08-01
Segmentation Fault in result2profile during search 3 2022-08-12 2022-09-08
IOS wallets crash when inputting amounts 5 2022-01-17 2022-07-02
[Installer]: allow custom config to be entered into Helm dependencies 3 2021-10-19 2022-09-14
meta: convert validation to ozzo 1 2020-10-06 2022-08-26
Proposal to improve Purview documentation about using REST-api 1 2022-02-07 2022-02-09
Replace deprecated `poll_interval` 0 2019-06-19 2022-09-15
Email verification 21 2021-03-12 2022-01-18
Use proper cursor positioning on Windows, or alternate screen buffer 3 2022-05-19 2022-09-24
Browser adaptation 2 2021-03-21 2022-01-23
Zulip does not wake up correctly in ferdi 5.6.3 beta 3 2 2021-10-28 2022-01-01
Realm Sync is not working in Flexible mode in React Native 1 2022-06-01 2022-08-05
API Key was automatically and unintentionally replaced with migration from 6 to 7.6 5 2022-03-01 2022-08-05
Missed error Stack Trace and Custom Attributes 6 2022-08-18 2022-09-06
'extends' option does not supported 1 2022-05-11 2022-09-16
Scrollbar issue in embedded videos 4 2021-07-08 2022-09-20
The application crashes when "Enter master password" window is open and you click on Accounts > Add Account 0 2021-05-28 2022-09-25
خطأ في اعادة التوجيه 2 2021-12-15 2022-09-26
egressgw: switch is_cluster_identity() to rely only on identities 0 2022-05-11 2022-07-02
How to install extra package in the offline machine ? 4 2022-04-29 2022-09-20
Add a peak filter to add a distinct classification 0 2021-07-12 2022-09-03
readme updates 2 2019-06-24 2022-01-12
Improve how text header values are rendered 1 2021-05-03 2022-09-15
配置TensorRT的动态shape参数 4 2021-11-12 2022-09-27
Add 0 to the number when renaming(重命名时对编号补0) 7 2021-10-22 2022-02-06
Autoscroll setting unexpectedly disabled 0 2021-10-07 2022-09-08
sqlite DB URI error check shows incorrect path 5 2022-05-27 2022-08-08
[Bug]: import() results in segment fault 4 2022-01-31 2022-09-23