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

Strange behaviour of the precision display option #20359

Closed
dexter2206 opened this issue Mar 15, 2018 · 2 comments · Fixed by #35212
Closed

Strange behaviour of the precision display option #20359

dexter2206 opened this issue Mar 15, 2018 · 2 comments · Fixed by #35212
Labels
Bug Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@dexter2206
Copy link

Consider the following example:

import pandas as pd
s = pd.Series([840.0, 4200.0])
pd.set_option('precision', 0)
print(s)
pd.set_option('precision',2)
print(s)

The first print produces 84, 420, while the second one produces correctly 840.0 and 4200.0.

Problem description

If I understand docs correctly, the precision option should affect only the number of digits after the decimal point, not the digits before it.

Expected Output

First print shows 840 and 4200 (or 840.0, 4200.0).

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.14.8-300.fc27.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: pl_PL.UTF-8
LOCALE: pl_PL.UTF-8

pandas: 0.22.0
pytest: 3.3.1
pip: 9.0.1
setuptools: 36.5.0
Cython: None
numpy: 1.14.2
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: 0.4.1
dateutil: 2.7.0
pytz: 2018.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.2
openpyxl: 2.4.9
xlrd: 1.0.0
xlwt: None
xlsxwriter: 1.0.2
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@WillAyd
Copy link
Member

WillAyd commented Mar 26, 2018

I think your bug is a result of the code in _trim_zeros linked below - care to take a look and try a PR?

def _trim_zeros(str_floats, na_rep='NaN'):

@dexter2206
Copy link
Author

@WillAyd sure, I'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants