Pandas version checks

  • [x] I have checked that this issue has not already been reported.

  • [x] I have confirmed this bug exists on the latest version of pandas.

  • [x] 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 : d9cdd2ee5a58015ef6f4d15c7226110c9aab8140 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

Comment From: Liam3851

Series.round explicitly delegates this to numpy for numpy dtyped-arrays (above your array will be np.float64 by default), and more generally follows the numpy convention here: https://numpy.org/doc/stable/reference/generated/numpy.round.html.

Comment From: rhshadrach

We also use PyArrow's compute on e.g. dtype=float64[pyarrow] which has the same behavior as NumPy.

https://arrow.apache.org/docs/python/generated/pyarrow.compute.round.html

I think adding that we use round-to-even to the documentation of Series.round and DataFrame.round would be welcome!

Comment From: palbha

I would like to take this up as my first PR - @rhshadrach I see the round to even already mentioned though - Can you suggest if there was anything specific you were thinking of ?

Image

Comment From: palbha

take