-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
% operator is inconsistent with Python / Numpy behaviour #3824
Comments
Having read up a bit about modulus on wikipedia, I am now a bit confused about what the strict definition of modulus is. Still, I'd expect the same behaviour of |
TL;DR.Whatever you do, make sure that # Python
assert((n//m)*m + (n%m) == n) Details:Modulo '%' is closely related to integer division. Typically, integer division comes first, then the modulo (remainder) is defined from the invariant |
This seems portable in current Rust https://doc.rust-lang.org/stable/std/primitive.i32.html#method.rem_euclid |
Again, it makes no sense to change '%' without simultaneously changing integer division (https://doc.rust-lang.org/stable/std/primitive.i32.html#method.div_euclid). Euclid algo is much slower than the native hardware implementation which goes contrary to polars stated goals. |
I will close this as the implementation language is Rust and we follow that behavior in this respect. |
What language are you using?
Python
Have you tried latest version of polars?
yes
What version of polars are you using?
0.13.50
What operating system are you using polars on?
Mac OS 12.3.1
What language version are you using
Python 3.10
Describe your bug.
In Rust, (and C, C++, D, C#, F# and Java), the % operator is the remainder. In Python (and Perl and Ruby), % is the modulus.
I would expect the python-style behaviour to be the one used by
%
, with perhaps the introduction of apl.remainder
.The text was updated successfully, but these errors were encountered: