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
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 ?
Comment From: palbha
take