Skip to content

make_date, make_timestamp(_ltz), add_months and months_between return the first row's result for every row when an argument is a literal #7712

Open

Description

@jonasdedden

Environment: daft 0.7.24, Python 3.14, Linux. The code involved is unchanged on main (865feff).

import datetime as dt
import daft
import daft.functions as F
from daft import col, lit

df = daft.from_pydict({
    "y": [2021, 2020, 2019],
    "m": [1, 6, 12],
    "d": [dt.date(2021, 1, 31), dt.date(2020, 6, 15), dt.date(2019, 12, 1)],
})
print(df.select(F.make_date(col("y"), col("m"), lit(1))).to_pydict())
print(df.select(F.add_months(col("d"), lit(1))).to_pydict())
print(df.select(F.months_between(col("d"), lit(dt.date(2019, 1, 1)))).to_pydict())

Actual: every row gets the first row's result.

make_date:      [2021-01-01, 2021-01-01, 2021-01-01]
add_months:     [2021-02-28, 2021-02-28, 2021-02-28]
months_between: [24.96774194, 24.96774194, 24.96774194]

Expected: [2021-01-01, 2020-06-01, 2019-12-01], [2021-02-28, 2020-07-15, 2020-01-01] and one value per row. With column arguments instead of literals (e.g. col("y") * 0 + 1 for the day) the results are correct.

The same happens for make_timestamp and make_timestamp_ltz (e.g. F.make_timestamp(col("y"), col("m"), lit(1), lit(0), lit(0), lit(0.0))).

Cause: the kernels combine their arguments with Iterator::zip (make_date, make_timestamp and make_timestamp_ltz in the same file, add_months and months_between in date_arithmetic.rs). A literal argument arrives as a length-1 series, so zip stops after the first row. The length-1 result is then broadcast to every row.

Suggested fix: broadcast every argument to the common length first (or reject mismatched lengths), as the other multi-argument kernels do.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions