Skip to content

BUG: EngFormatter accuracy wrong #62963

@cparg

Description

@cparg

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

from pandas.io.formats.format import EngFormatter

def test_eng_formatter():
    formatter4 = EngFormatter(use_eng_prefix=True, accuracy=4)
    formatter5 = EngFormatter(use_eng_prefix=True, accuracy=5)

    assert formatter4(12_345_678.90)   == "123.5M"
    assert formatter5(12_345_678.90)   == "123.46M"
    assert formatter4(0.0001234567890) == "123.5u"
    assert formatter5(0.01234567890)   == "12.346m"

test_eng_formatter()

Issue Description

The accuracy argument of the EngFormatter is generating a different number of digits.

It is expected to obtain 5 digits in total with accuracy=5, but the argument seems to affect only the digits behind the decimal point. This is wrong. It is not Engineering Notation !

Expected Behavior

Example:
with accuracy=4

  • 12_345_678.90 returns 12.3457M , expected : 12.35M
  • 123.4568u returns 123.4568u, expected 123.5u

with accuracy=5

  • 12_345_678.90 returns 12.34568M, expected 12.345M
  • 0.01234567890 returns 12.34568m, expected 12.346m

Installed Versions

INSTALLED VERSIONS ------------------ commit : 9c8bc3e python : 3.9.21 python-bits : 64 OS : Linux OS-release : 6.17.5-1.el9.elrepo.x86_64 Version : #1 SMP PREEMPT_DYNAMIC Thu Oct 23 13:22:49 EDT 2025 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : de_DE.UTF-8 LOCALE : de_DE.UTF-8

pandas : 2.3.3
numpy : 2.0.2
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 21.3.1
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : 4.6.5
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions