polars
polars copied to clipboard
mod seemingly dispatches to the rust remainder operator rather than the modulo operator
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 Polars.
Reproducible example
import polars as pl
import numpy as np
x = 2.1
df = pl.DataFrame({'x':x})
print(x % 2) # Prints 0.1
print(np.mod(x,2)) # Prints 0.1
print(df.select(pl.col('x').mod(2))) # Prints 0.1
x = -.1
df = pl.DataFrame({'x':x})
print(x % 2) # Prints 1.9
print(np.mod(x,2)) # Prints 1.9
print(df.select(pl.col('x').mod(2))) #Prints -0.1
This originated at this SO question
Issue description
I found this which confirms BallPointBen's assertion that there's a mismatch in operators.
Expected behavior
mod should match the python % operator and np.mod
Installed versions
--------Version info---------
Polars: 0.18.15
Index type: UInt32
Platform: Linux-5.10.102.1-microsoft-standard-WSL2-x86_64-with-glibc2.31
Python: 3.10.12 (main, Jun 7 2023, 19:32:10) [GCC 10.2.1 20210110]
----Optional dependencies----
adbc_driver_sqlite: <not installed>
cloudpickle: <not installed>
connectorx: 0.3.1
deltalake: <not installed>
fsspec: 2023.6.0
matplotlib: <not installed>
numpy: 1.25.2
pandas: 2.0.3
pyarrow: 12.0.1
pydantic: 2.1.1
sqlalchemy: <not installed>
xlsx2csv: 0.8.1
xlsxwriter: 3.1.2