Daft icon indicating copy to clipboard operation
Daft copied to clipboard

ability to cast python timedelta to `Duration`

Open universalmind303 opened this issue 4 months ago • 0 comments

Is your feature request related to a problem? Please describe.

I want to be able to cast a timedelta to a duration the same way we implicitly convert it if using from_pydict

import daft
import datetime

df = daft.from_pydict(
    {
        "time_delta": [datetime.timedelta(days=1), datetime.timedelta(days=2)],
    }
)
df.collect()

╭────────────────────────╮
│ time_delta             │
│ ---                    │
│ Duration[Microseconds] │
╞════════════════════════╡
│ 86400000000            │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 172800000000           │
╰────────────────────────╯
(Showing first 2 of 2 rows)

Describe the solution you'd like

df.select(daft.lit(datetime.timedelta(days=1)).cast(daft.DataType.duration('us')))

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

universalmind303 avatar Oct 03 '24 17:10 universalmind303