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.format.thousands" option doesn't work for integers #58737

Closed
2 of 3 tasks
vladpy8 opened this issue May 16, 2024 · 4 comments
Closed
2 of 3 tasks

BUG: "styler.format.thousands" option doesn't work for integers #58737

vladpy8 opened this issue May 16, 2024 · 4 comments
Labels
Closing Candidate May be closeable, needs more eyeballs Usage Question

Comments

@vladpy8
Copy link

vladpy8 commented May 16, 2024

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
pandas.set_option('styler.format.thousands', ',')

data = pandas.DataFrame(data=[{'field': 1234567890}], dtype='int64',)

# Doesn't output integer field with comma separator
data

# Does output integer field with comma separator
data.style.format(thousands=',')

Issue Description

Printing data without .style in jupyter cell displays huge integer number without comma separator, inspite of the option set
Printing data with .style in jupyter cell displays integers with commas

Expected Behavior

Outputs must be same

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.11.9.final.0
python-bits : 64
OS : Darwin
OS-release : 23.4.0
Version : Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8

pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 69.5.1
pip : 24.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.1.4
IPython : 8.24.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.5.0
gcsfs : None
matplotlib : 3.9.0
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 10.0.1
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : 2024.5.0
scipy : 1.13.0
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

@vladpy8 vladpy8 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 16, 2024
@vladpy8 vladpy8 changed the title BUG: BUG: "styler.format.thousands" option doesn't work for integers May 16, 2024
@attack68
Copy link
Contributor

attack68 commented May 17, 2024

Agreed. This needs fixing, also for decimal option.

The solution, I believe, is in style_render:

#edited out

change to:

#edited out

and replace all the defaultdicts with the new ddict.

Needs tests.

@attack68 attack68 added Styler conditional formatting using DataFrame.style good first issue and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 17, 2024
@attack68
Copy link
Contributor

The above was not correct. The following works:

pd.set_option('styler.format.precision', 3)
pd.set_option('styler.format.thousands', "+")
pd.set_option('styler.format.decimal', "-")
df = pd.DataFrame([
    [10000.0, 20000],
    [30000.0, 40000]
])
df.style

Screenshot 2024-05-18 at 07 43 45

as does

pd.set_option('styler.format.precision', 3)
pd.set_option('styler.format.thousands', "+")
pd.set_option('styler.format.decimal', "-") 
df = pd.DataFrame(data=[{'field': 1234567890}], dtype='int64',)
df.style

Screenshot 2024-05-18 at 07 46 10

I misread your issue. The styler pandas options only impact the Styler class. These options are available for people who regularly use Styler. They do not impact DataFrame and the options associated with that class and any of its data input, wrangling, or (in your case) output methods. This is desired behaviour.
If your do not call .style you will not produce a Styler and these options will not apply.

@attack68 attack68 added Closing Candidate May be closeable, needs more eyeballs Usage Question and removed Bug good first issue Styler conditional formatting using DataFrame.style labels May 18, 2024
@mroeschke
Copy link
Member

Yeah given the above it seems like the OP is the expected behavior so closing

@vladpy8
Copy link
Author

vladpy8 commented May 20, 2024

The styler pandas options only impact the Styler class.

They do not impact DataFrame and the options associated with that class and any of its data input, wrangling, or (in your case) output methods.

I see, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closing Candidate May be closeable, needs more eyeballs Usage Question
Projects
None yet
Development

No branches or pull requests

3 participants