-
Notifications
You must be signed in to change notification settings - Fork 8
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
month_delta return incorrect value if passed a date object #84
Comments
thanks @pounde for the report could you include a reproducible example please? If I run
then I do indeed get an error
|
Apologies for not doing that from the start. I can't seem to replicate my code, nor can I replicate the code you posted. It is also worth noting that the object passed in the original issue was a 'date' object, not 'datetime'. I have updated the title to reflect that. While attempting to run the code you provided, I get: [line 22](vscode-notebook-cell:?execution_count=36&line=22)InvalidOperationError: Series month_delta, length 1 doesn't match the DataFrame height of 5
If you want expression: col("start_date")./usr/local/lib/python3.10/site-packages/polars_xdt/_internal.abi3.so:month_delta([2023-02-28]) to be broadcasted, ensure it is a scalar (for instance by adding '.first()'). Not sure why I didn't get this before, nor why it can't be broadcast. |
are you sure you got that while running the code I posted? could you post the full traceback please? |
Apologies for the long tail. I created a fresh env:
I still get the shape error. The stacktrace is:
Thus far, I'm unable to replicate the issue I had so it may well have been user error. Let me know if there is more I can provide to help. |
Thanks Sure, that should probably broadcast - @akmalsoliev fancy taking this on, as you'd introduced the feature? |
So, the issue is: from datetime import date, datetime
import polars as pl
import polars_xdt as xdt
df = pl.DataFrame(
{
"start_date": [
date(2024, 3, 1),
date(2024, 3, 31),
date(2022, 2, 28),
date(2023, 1, 31),
date(2019, 12, 31),
],
"end_date": [
date(2023, 2, 28),
date(2023, 2, 28),
date(2023, 2, 28),
date(2023, 1, 31),
date(2023, 1, 1),
],
},
)
print(df.with_columns(
xdt.month_delta("start_date", date(2023, 2, 28)).alias("month_delta")
)) outputs: InvalidOperationError: Series month_delta, length 1 doesn't match the DataFrame height of 5
If you want expression: col("start_date")./home/marcogorelli/scratch/.venv/lib/python3.12/site-packages/polars_xdt/_internal.abi3.so:month_delta([2023-02-28]) to be broadcasted, ensure it is a scalar (for instance by adding '.first()'). |
Hey, interesting issue, this shouldn't happen, there should be an error raised that Line 120 in aa2e214
this works fine from datetime import date
import polars as pl
import polars_xdt as xdt
df = pl.DataFrame(
{
"start_date": [
date(2024, 3, 1),
date(2024, 3, 31),
date(2022, 2, 28),
date(2023, 1, 31),
date(2019, 12, 31),
],
"end_date": [
date(2023, 2, 28),
date(2023, 2, 28),
date(2023, 2, 28),
date(2023, 1, 31),
date(2023, 1, 1),
],
},
)
df = df.with_columns(test=date(2023, 2, 28)).with_columns(
result=xdt.month_delta("start_date", "test")
)
print(df) out:
|
I am attempting to replicate the functionality of relativedelta. The month_delta meets my current purposes but it return incorrect values if passed a date object.
This provided incorrect results. I would expect correct values or a ValueError
The following was my workaround:
The text was updated successfully, but these errors were encountered: