Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Styler renders booleans True/False as digits since 1.4.0 #46384

Closed
3 tasks done
ihayhurst opened this issue Mar 16, 2022 · 6 comments · Fixed by #46548
Closed
3 tasks done

BUG: Styler renders booleans True/False as digits since 1.4.0 #46384

ihayhurst opened this issue Mar 16, 2022 · 6 comments · Fixed by #46548
Labels
Bug Needs Tests Unit test(s) needed to prevent regressions Regression Functionality that used to work in a prior pandas version Styler conditional formatting using DataFrame.style
Milestone

Comments

@ihayhurst
Copy link

ihayhurst commented Mar 16, 2022

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

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
Screenshot 2022-03-16 at 00 11 04

Expected Behavior

species extinct
0 parrot False
1 dodo True
2 moa True
3 whale False
species object
extinct bool
dtype: object
Screenshot 2022-03-16 at 00 08 18

Installed Versions

INSTALLED VERSIONS

commit : 06d2301
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

@ihayhurst ihayhurst added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 16, 2022
@attack68
Copy link
Contributor

attack68 commented Mar 16, 2022

I do not see this problem on Master. Running the following on Master:

>>> df1 = DataFrame({"A": [True, False]})
>>> print(df1.style.to_html())
<style type="text/css">
</style>
<table id="T_f4541">
  <thead>
    <tr>
      <th class="blank level0" >&nbsp;</th>
      <th id="T_f4541_level0_col0" class="col_heading level0 col0" >A</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th id="T_f4541_level0_row0" class="row_heading level0 row0" >0</th>
      <td id="T_f4541_row0_col0" class="data row0 col0" >True</td>
    </tr>
    <tr>
      <th id="T_f4541_level0_row1" class="row_heading level0 row1" >1</th>
      <td id="T_f4541_row1_col0" class="data row1 col0" >False</td>
    </tr>
  </tbody>
</table>

@attack68 attack68 added Needs Info Clarification about behavior needed to assess issue Styler conditional formatting using DataFrame.style Closing Candidate May be closeable, needs more eyeballs labels Mar 16, 2022
@ihayhurst
Copy link
Author

Ok, sorry looks like I have this in the released version of pandas 1.4.1 but checking out master and using the docker container 1.5.0.dev it's fixed I should have read the check box release and master more carefully.
Would be grateful if you know where the issue that fixed it is as I couldn't find any reference to it

INSTALLED VERSIONS

commit : e7a0cf3
python : 3.8.12.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.76-linuxkit
Version : #1 SMP Mon Nov 8 10:21:19 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : C.UTF-8
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.0.dev0+543.ge7a0cf3ba0
numpy : 1.22.3

@attack68
Copy link
Contributor

I believe it is #46119.

Looks like isinstance(True, int) = True whereas is_integer(True) = False

simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Mar 25, 2022
@simonjayhawkins simonjayhawkins added Regression Functionality that used to work in a prior pandas version Needs Tests Unit test(s) needed to prevent regressions and removed Needs Info Clarification about behavior needed to assess issue Needs Triage Issue that has not been reviewed by a pandas team member Closing Candidate May be closeable, needs more eyeballs labels Mar 25, 2022
@simonjayhawkins simonjayhawkins added this to the 1.4.2 milestone Mar 25, 2022
@simonjayhawkins
Copy link
Member

Reopened to at least add a test before closing. Milestoned 1.4.2 for now to track pending discussion in #46500

@simonjayhawkins
Copy link
Member

I believe it is #46119.

can confirm, reverting #46119 results in code sample in #46384 (comment) giving same result as 1.4.1

@simonjayhawkins
Copy link
Member

Datatype boolean in dataframe is now rendered as digits when passed to styler since version 1.4.0

can confirm regression from 1.3.5

first bad commit: [08ac29a] ENH: styler.format options (#43256)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Tests Unit test(s) needed to prevent regressions Regression Functionality that used to work in a prior pandas version Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants