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 arithmetic operations between numeric List Series and a scalar #18900

Open
itamarst opened this issue Sep 24, 2024 · 1 comment
Open
Labels
enhancement New feature or an improvement of an existing feature

Comments

@itamarst
Copy link
Contributor

Description

A follow-up to #9188 and #8006.

Multiplying a numeric Series by a scalar works, but currently doing the same with a list fails; this should be fixed for consistency with new ability to do arithmetic between List Series (#9188) and List series and numeric series (#8006):

>>> s = pl.Series([1, 2])
>>> s * 2
shape: (2,)
Series: '' [i64]
[
        2
        4
]
>>> s = pl.Series([[1, 2]])
>>> s * 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/itamarst/devel/polars/py-polars/polars/series/series.py", line 1136, in __mul__
    return self._arithmetic(other, "mul", "mul_<>")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/itamarst/devel/polars/py-polars/polars/series/series.py", line 1022, in _arithmetic
    other = maybe_cast(other, self.dtype)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/itamarst/devel/polars/py-polars/polars/datatypes/convert.py", line 350, in maybe_cast
    raise TypeError(msg) from None
TypeError: cannot convert Python type 'int' to List(Int64)
@itamarst itamarst added the enhancement New feature or an improvement of an existing feature label Sep 24, 2024
@itamarst
Copy link
Contributor Author

I think this overlaps with the in-progress PR #18858, so might be able to build on that.

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