-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
depr(python): Rename map_dict
to replace
and change default behavior
#12599
Conversation
Nice, can we take this opportunity to sometimes decide to go to a when -> then -> otherwise? |
When would it be preferable, though? I guess for a single value you'd generally want to use I'd like to just re-implement this whole function on the Rust side regardless. We can pick that up in a separate PR and include performance improvements then? |
For a single value indeed. |
Essentially immediately... I was timing this at work the other day and With a release build from current HEAD: from codetiming import Timer
import polars as pl
df = pl.DataFrame({"x": range(10_000_000)})
with Timer("when/then"):
res = df.with_columns(
y = pl.when(pl.col("x") == 3).then("!!").when(pl.col("x") == 9_999_998).then("##")
)
# Elapsed time: 0.1122 seconds
with Timer("map_dict"):
res = df.with_columns(
y = pl.col("x").map_dict({3:"!!", 9_999_998:"##"})
)
# Elapsed time: 0.0581 seconds
We'd probably get more mileage from an optimisation that goes the other way, detecting patterns like this in |
Yeap, that's what I expect. A single value to when then otherwise, the rest via map_dict. |
e6e7777
to
74bb679
Compare
Closes #10755
This has come up many times (e.g. #10744, #12537, #12533, ...) and I've been putting off making a decision on this. I think this is the way to go.
See #10755 (comment) for justification.
Changes
map_dict
toreplace
default=None
.