Skip to content

Commit

Permalink
fix(python): address an inadvertently shallow-copy issue on underlyin…
Browse files Browse the repository at this point in the history
…g PySeries
  • Loading branch information
alexander-beedie committed Jul 26, 2023
1 parent d872844 commit c342e7a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions py-polars/polars/utils/_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ def nt_unpack(obj: Any) -> Any:


def series_to_pyseries(name: str, values: Series) -> PySeries:
"""Construct a PySeries from a Polars Series."""
py_s = values._s
"""Construct a new PySeries from a Polars Series."""
py_s = values._s.clone()
py_s.rename(name)
return py_s

Expand Down
8 changes: 8 additions & 0 deletions py-polars/tests/unit/operations/test_is_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

import polars as pl
from polars.testing import assert_series_equal


def test_struct_logical_is_in() -> None:
Expand Down Expand Up @@ -101,3 +102,10 @@ def test_is_in_series() -> None:

with pytest.raises(pl.ComputeError, match=r"cannot compare"):
df.select(pl.col("b").is_in(["x", "x"]))

# check we don't shallow-copy and accidentally modify 'a' (see: #10072)
a = pl.Series("a", [1, 2])
b = pl.Series("b", [1, 3]).is_in(a)

assert a.name == "a"
assert_series_equal(b, pl.Series("b", [True, False]))

0 comments on commit c342e7a

Please sign in to comment.