-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Description
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.DataFrame([[-0.025]]).round(2).values)
print (pd.DataFrame([[-0.025001]]).round(2).values)
print (round(-0.025, 2))
print (round(-0.025001, 2))
#output:
#[[-0.02]]
#[[-0.03]]
#-0.03
#-0.03
Issue Description
I would expect all values to be -0.03 but pandas rounds -0.025 to -0.02. I suspect this is due to bankers rounding, which would be fine, but it also looks like pandas doesn't mimic the native python rounding behaviour, which rounds both to -0.03 - this might trip people up.
Expected Behavior
Round -0.025 to -0.03, or if this explicitly avoided as part of your rounding strategy, at least make your strategy match the python round function.
Installed Versions
INSTALLED VERSIONS
commit : d9cdd2e
python : 3.10.15.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22631
machine : AMD64
processor : Intel64 Family 6 Model 186 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en
LOCALE : English_United Kingdom.1252
pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 75.1.0
pip : 22.3.1
Cython : None
pytest : 8.3.4
hypothesis : None
sphinx : 7.3.7
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.4
IPython : 8.27.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : 1.3.7
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.9.2
numba : None
numexpr : 2.10.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.14.1
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : 2.4.1
pyqt5 : None