-
Notifications
You must be signed in to change notification settings - Fork 136
Spark expr replace strict #2254
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
base: main
Are you sure you want to change the base?
Spark expr replace strict #2254
Conversation
mapping_expr = self._F.create_map(old, new) | ||
return mapping_expr[_input] | ||
|
||
result = self._from_call(_replace_strict, "replace_strict", old=old, new=new) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most likely confusing myself with this self._from_call
...
The approach I'm taking is to use pyspark.sql.functions.create_map
to create a mapping expression for us. Currently, it only accepts one constant for old
and another constant for new
(and a return_dtype
).
Running into two issues when trying to expand the functionality:
- if the user passes a sequence of values to replace,
self._from_call
will convertold
andnew
into array columns; instead, I wantold
andnew
to be a sequence of columns by the time we access it in_replace_strict
so that we can use it withcreate_map
- this approach doesn't allow us to pass expressions to
old
ornew
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your pr!
i don't think we currently accept expressions here for other backends anyway, so I think we don't need to support that just yet
@lucas-nelson-uiuc I was a bit confused when I saw (#2253) So right now narwhals/narwhals/_compliant/expr.py Lines 827 to 847 in a279634
That is why you're seeing However, if narwhals/narwhals/_compliant/expr.py Line 846 in a279634
Into each of these sections: narwhals/narwhals/_dask/expr.py Lines 632 to 634 in a279634
narwhals/narwhals/_duckdb/expr.py Lines 488 to 502 in a279634
I hope that all makes sense, but let me know if you have any issues π |
What type of PR is this? (check all applicable)
Related issues
replace_strict
for SparkLikeΒ #2253Checklist
If you have comments or can explain your changes, please do so below
Currently supports replacing one value with another value and specifying
return_dtype
. See comments for issue I'm running into.