Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support datetime arithemetic within lists #18899

Open
itamarst opened this issue Sep 24, 2024 · 0 comments
Open

Support datetime arithemetic within lists #18899

itamarst opened this issue Sep 24, 2024 · 0 comments
Labels
enhancement New feature or an improvement of an existing feature

Comments

@itamarst
Copy link
Contributor

Description

This is a follow-up to #9188 and #8006.

Much like adding lists to each other is (or for some cases, soon will be) working for numbers, it can also be made to work for dates, datetimes, and durations.

For example, adding these two series works:

>>> import polars as pl
>>> from datetime import date, timedelta
>>> s = pl.Series([timedelta(days=2), timedelta(days=3)])
>>> s2 = pl.Series([timedelta(days=2), timedelta(days=3)])
>>> s + s2
shape: (2,)
Series: '' [date]
[
        2007-01-02
        2006-01-04
]

But nested as a list, it doesn't work:

>>> s = pl.Series([[date(2006, 12, 31), date(2006, 1, 1)]])
>>> s2 = pl.Series([[timedelta(days=2), timedelta(days=3)]])
>>> s + s2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/itamarst/devel/polars/py-polars/polars/series/series.py", line 1051, in __add__
    return self._arithmetic(other, "add", "add_<>")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/itamarst/devel/polars/py-polars/polars/series/series.py", line 997, in _arithmetic
    return self._from_pyseries(getattr(self._s, op_s)(other._s))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
polars.exceptions.InvalidOperationError: casting from Duration(Microseconds) to Date not supported
@itamarst itamarst added the enhancement New feature or an improvement of an existing feature label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant