-
Notifications
You must be signed in to change notification settings - Fork 123
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
[Bug]: is_between incorrect behaviour (TypeError: cannot create expression literal for value of type Expr) #1659
Comments
Thanks for the report! |
You're welcome! Thanks for this fantastic tool. BTW I am doing this as a temporal fix:
|
thanks! will try to include a fix in next monday's release. just out of interest, what are you using narwhals for? another workaround might be .filter(
nw.col(col_time).is_between(start_time, end_time, closed="both")
) |
I prefer to use the other one so I don't create any new column :) I am using Narwhals for an internal library that deals with ML preprocessing. Our team used to work using pandas but some of us are migrating to Polars. This way we can use both :) |
BTW I just saw that when using that function with pandas I can't use the date thing: I can imagine that (at this moment) if the format is YYYY-MM-dd I can use < and > since they are comparable as strings, right? |
Hey @sergiocalde94 thanks for reporting the issue! #730 goes into a similar direction. Allowing for expressions is extremely flexible but not fully supported just yet! Maybe it could be in scope as one of 2025 goals 😉 |
Describe the bug
When attempting to use nw.lit to create literal expressions for filtering dates in a Narwhal DataFrame, the following error occurs:
TypeError: cannot create expression literal for value of type Expr.
This happens specifically when using nw.lit in combination with
.filter()
and.is_between()
for date-based comparisons. However, casting and aliasing the literals and then using them in.to_native()
before filtering resolves the issue (but I can't do this since I want to have agnostic dataframe filtering.Steps or code to reproduce the bug
Setup:
then:
to get the error and:
to get the expected results.
Expected results
Actual results
TypeError: cannot create expression literal for value of type Expr.
Please run narwhals.show_version() and enter the output below.
Relevant log output
The text was updated successfully, but these errors were encountered: