I have a rather technical question about the polars library. I have looked for a polars-specific forum, but have not been able to find it. If someone would be able to point me to the proper place to ask this question, that would be very helpful.
For completeness, here is the question:
Edit
I realise wrote the question a little poorly. The code probably isn’t as self-explanatory as I intended. The output of the scalar case (which works) is
basic | array |
---|---|
i32 | array[i32, 4] |
0 | [0, 1, 2, 3] |
1 | [1, 2, 3, 4] |
2 | [2, 3, 4, 5] |
3 | [3, 4, 5, 6] |
I’d like to be able to create a similar output for the datetime case.
I would like to be able to do something like the following:
from datetime import UTC, datetime, timedelta
import numpy as np
import polars as pl
start = datetime(2025, 4, 1, 15, 0, tzinfo=UTC)
series_1 = pl.Series(
"datetime_3pm",
[start + timedelta(minutes=30 * i) for i in range(4)]
)
array = np.array([timedelta(minutes=30 * i) for i in range(4)])
series_1 + array
but this raises SchemaError: failed to determine supertype of i32 and object
.
I think this should be possible, because for example the following code works:
import numpy as np
import polars as pl
basic_series = pl.Series(range(4), dtype=pl.Int32)
array = np.arange(4, dtype=np.int32).reshape((1, 4))
array_series = basic_series + array
df = pl.DataFrame({"basic": basic_series})
df.with_columns(
array=pl.col("basic") + array
)
I’ve tried a lot of different things by this point.
I’ve got a workaround for my algorithm where I do an outer join instead of creating an array column. But it bothers me that I don’t know how to make this[1] work.
Any help would be appriciated
adding a timedelta array to a datetime column ↩︎