polars-xdt icon indicating copy to clipboard operation
polars-xdt copied to clipboard

month_delta return incorrect value if passed a datetime

Open pounde opened this issue 4 months ago • 1 comments

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

    df_ = df.filter(pl.col("date") <= end_date).with_columns(
        yr_for_calc=xdt.month_delta(pl.col("date"), end_date) / 12
    )

The following was my workaround:

    df_ = (
        df.filter(pl.col("date") <= end_date)
        .with_columns(end_date=end_date)
        .with_columns(
            yr_for_calc=xdt.month_delta(pl.col("date"), pl.col("end_date")) / 12
        )
    ).drop("end_date")

pounde avatar Oct 05 '24 17:10 pounde