Closed kl31tz closed 4 days ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 79.45%. Comparing base (
8facee9
) to head (a9fb5df
). Report is 1 commits behind head on main.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
🚨 Try these New Features:
Maybe related to #17798
right ! I did not notice np.ndarray
did not define __round__
either
Strange considering its round()
method/functions all do banker rounding, and therefore are all consistent consistent w/ python
>>> import numpy as np
>>> np.round(np.arange(6) + .5)
array([0., 2., 2., 4., 4., 6.])
>>> [round(i + .5) for i in range(6)]
[0, 2, 2, 4, 4, 6]
>>> round(np.arange(6) + .5)
Traceback (most recent call last):
File "<python-input-3>", line 1, in <module>
round(np.arange(6) + .5)
~~~~~^^^^^^^^^^^^^^^^^^^
TypeError: type numpy.ndarray doesn't define __round__ method
For polars it is trickier if Series.round
and python round
differ
>>> import polars as pl
>>> pl.int_range(6, eager=True).round()
shape: (6,)
Series: 'literal' [i64]
[
0
1
2
3
4
5
]
I don't think we should do this. I don't think we should implement all python dunders. I don't see much benefit as it adds different ways of doing stuff. Another reasons is that our rounding behavior is not equal to python's.
understood, I'll close the issue thank you for taking a look !
Hello polars maintainers,
This is a PR to add support for builtin
round
by implementing__round__
in Expr and Series; It is already possible to callabs(e)
ande.abs()
on series and expressions; this change enables callinground(e)
orround(e, 3)
in addition toe.round()
ore.round(3)
Let me know if you'd like to support this feature and whether I can contribute further by implementing it in other areas
resolves https://github.com/pola-rs/polars/issues/19942
Thank you !