BUG: Styler renders booleans True/False as digits since 1.4.0
See original GitHub issuePandas 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
d = {
"species": ["parrot", "dodo", "moa", "whale"],
"extinct": [False, True, True, False],
}
df = pd.DataFrame(data=d)
print(df.head())
print(df.dtypes)
def applyStyle(df):
style = [
dict(
selector="th",
props=[
("font-size", "100%"),
("text-align", "left"),
("text-transform", "capitalize"),
("background-color", "#333399"),
("color", "white"),
],
),
dict(selector="caption", props=[("caption-side", "bottom")]),
dict(selector="td a", props=[("display", "block")]),
]
patchingStyle = (
df.style.set_table_styles(style)
.set_properties(subset=["species"], **{"width": "200px"})
.set_properties(subset=["extinct"], **{"width": "130px"})
)
return patchingStyle
html = applyStyle(df).to_html(doctype_html=True)
with open("test.html", "w", encoding="utf-8") as f:
f.write(html)
Issue Description
Datatype boolean in dataframe is now rendered as digits when passed to styler since version 1.4.0
species extinct 0 parrot False 1 dodo True 2 moa True 3 whale False species object extinct bool dtype: object
Expected Behavior
species extinct 0 parrot False 1 dodo True 2 moa True 3 whale False species object extinct bool dtype: object
Installed Versions
INSTALLED VERSIONS
commit : 06d230151e6f18fdb8139d09abf539867a8cd481 python : 3.9.5.final.0 python-bits : 64 OS : Darwin OS-release : 19.6.0 Version : Darwin Kernel Version 19.6.0: Thu Jan 13 01:26:33 PST 2022; root:xnu-6153.141.51~3/RELEASE_X86_64 machine : x86_64 processor : i386 byteorder : little LC_ALL : None LANG : en_GB.UTF-8 LOCALE : en_GB.UTF-8
pandas : 1.4.1 numpy : 1.20.3 pytz : 2021.1 dateutil : 2.8.1 pip : 22.0.4 setuptools : 56.0.0 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 3.0.1 IPython : 7.24.1 pandas_datareader: None bs4 : None bottleneck : None fastparquet : None fsspec : None gcsfs : None matplotlib : 3.4.2 numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : 1.6.3 sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None xlwt : None zstandard : None None
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (5 by maintainers)
Top GitHub Comments
can confirm regression from 1.3.5
first bad commit: [08ac29ab685d5e488a5b122944f8ee2f5000b6c9] ENH:
styler.format
options (#43256)can confirm, reverting #46119 results in code sample in https://github.com/pandas-dev/pandas/issues/46384#issuecomment-1068786611 giving same result as 1.4.1