Skip to content

BUG: excess precision when printing float32 values #71916

Open

Description

@jdemeyer

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
print(pd.Series([100.1], dtype="float32"))

Issue Description

Pandas does not make a difference in how it displays float32 and float64 values, resulting in excess precision:

>>> import pandas as pd
>>> s = pd.Series([100.1], dtype="float32"); s
0    100.099998
dtype: float32
>>> print(s.iloc[0])  # Print the raw numpy.float32
100.1
>>> s.to_numpy()
array([100.1], dtype=float32)

Pandas prints 100.099998 while Numpy knows that it's a float32 and prints it as 100.1. I'm well aware that this may be working as intented because of the default 6-digits precision that Pandas uses. This works well for float64 but not so much for float32.

Note that this issue is specifically about printing the series (including Jupyter's pretty-printed table display) and is unrelated to conversions like s.to_list(). Also note that round() doesn't help, as the issue is really with the display of the underlying float32 value and round() doesn't change that:

>>> import pandas as pd
>>> pd.Series([100.1], dtype="float32").round(1)
0    100.099998
dtype: float32

Expected Behavior

>>> import pandas as pd
>>> s = pd.Series([100.1], dtype="float32"); s
0    100.1
dtype: float32

Installed Versions

Details

INSTALLED VERSIONS

commit : 3dcc6fb
python : 3.14.4
python-bits : 64
OS : Linux
OS-release : 6.6.87.2-microsoft-standard-WSL2
Version : #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : C.UTF-8

pandas : 3.1.1
numpy : 2.5.2
dateutil : 2.9.0.post0
pip : None
Cython : None
sphinx : None
IPython : 9.12.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.14.3
bottleneck : None
fastparquet : None
fsspec : None
html5lib : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : None
matplotlib : 3.10.8
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.5
psycopg2 : None
pymysql : None
pyarrow : 25.0.1
pyiceberg : None
pyreadstat : None
pytest : 9.1.1
python-calamine : None
pytz : 2026.2
pyxlsb : None
s3fs : None
scipy : 1.17.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
qtpy : None
pyqt5 : None

Activity

  1. added
    Needs TriageIssue that has not been reviewed by a pandas team member
    on Nov 5, 2026
  2. Rudra-G-23 commented on Nov 7, 2026

    @Rudra-G-23

    Hi, I'd be interested in working on this issue once it's triaged.

    Before proceeding, could you clarify whether the preferred fix is to use the shortest round-trippable representation for float32 values or preserve the existing display.precision behavior?

    I can work on the fix and add regression tests once the expected behavior is confirmed.

  3. rhshadrach commented on Nov 7, 2026

    @rhshadrach
    Member

    Thanks for the report. Previously this was fixed for conversion to string (#36451); agreed we shouldn't trip through float64 when printing out these values.

    A PR to fix this should also fix the Float32 and float32[pyarrow] cases along with float32.

  4. added
    Output-Formatting__repr__ of pandas objects, to_string
    and removed
    Needs TriageIssue that has not been reviewed by a pandas team member
    on Nov 7, 2026
  5. Rudra-G-23 commented on Nov 8, 2026

    @Rudra-G-23

    /take

  6. jdemeyer commented on Nov 8, 2026

    @jdemeyer
    Author

    could you clarify whether the preferred fix is to use the shortest round-trippable representation for float32 values or preserve the existing display.precision behavior?

    Probably a combination of both, something like:

    1. Determine the number of digits after the decimal point in the shortest decimal representation.
    2. If that number of digits is at most display.precision, use that shortest decimal. Otherwise, print display.precision number of digits as before.

    A PR to fix this should also fix the Float32 and float32[pyarrow] cases along with float32.

    Actually, why not all floats? The fix that I suggested above might as well be applied for float64 too. I don't expect it would make much difference in practice for the default precision, but it's good to be consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions