Inconsistent type casting of datetime
in functions on List
column
#19917
Labels
bug
Something isn't working
needs triage
Awaiting prioritization by a maintainer
python
Related to Python Polars
Checks
Reproducible example
Apologies - I didn't have time to try the following functions that also appear to be in the same namespace:
Log output
No response
Issue description
Some list functions preserve
datetime
type, some cast tof64
, and some error.In my use case, I have a dataframe with two list columns: one holds sensor readings, the other holds timestamps. I want the average value of the sensor column, and the average timestamp.
Ideally, I would like to just use
pl.col("timestamps").list.mean()
and get a datetime object with the same precision, corresponding to the average timestamp.Currently, the
.mean()
function in this context runs without error, but gives af64
result that I think represents number of units since unix epoch. So far, most polars functions I have tried which handledatetime
preserve the "datetime"-ness correctly, even when exporting to native python objects/numpy/etc..first()
works fine, implying that indexing over a list ofdatetime
is fine..min()
works fine, implying that numeric comparison ofdatetime
is supported..sum()
errors. Not sure whether it should error or not. Since the average of a list of timestamps makes intuitive sense, and sum is simply average divided by length, then perhaps sum should be defined.I added a bunch of simple examples above in the hope that it might be useful for exploring this behavior or adding unit tests. Please let me know if more info is useful.
Expected behavior
Installed versions
The text was updated successfully, but these errors were encountered: