Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/py-polars/tests/unit/series/test_extend.py
6939 views
1
import pytest
2
3
import polars as pl
4
from polars.testing import assert_series_equal
5
6
7
def test_extend() -> None:
8
a = pl.Series("a", [1, 2])
9
b = pl.Series("b", [8, 9, None])
10
11
result = a.extend(b)
12
13
expected = pl.Series("a", [1, 2, 8, 9, None])
14
assert_series_equal(a, expected)
15
assert_series_equal(result, expected)
16
assert a.n_chunks() == 1
17
18
19
def test_extend_self() -> None:
20
a = pl.Series("a", [1, 2])
21
22
a.extend(a)
23
24
expected = pl.Series("a", [1, 2, 1, 2])
25
assert_series_equal(a, expected)
26
assert a.n_chunks() == 1
27
28
29
def test_extend_bad_input() -> None:
30
a = pl.Series("a", [1, 2])
31
b = a.to_frame()
32
33
with pytest.raises(
34
TypeError,
35
match="expected `other` .*to be a 'Series'.* not 'DataFrame'",
36
):
37
a.extend(b) # type: ignore[arg-type]
38
39
with pytest.raises(
40
TypeError,
41
match="expected `other` .*to be a 'Series'.* not 'LazyFrame'",
42
):
43
a.extend(b.lazy()) # type: ignore[arg-type]
44
45
46
def test_extend_with_null_series() -> None:
47
a = pl.Series("a", [1, 2], pl.Int64)
48
b = pl.Series("b", [None, None], pl.Null)
49
50
result = a.extend(b)
51
52
expected = pl.Series("a", [1, 2, None, None], pl.Int64)
53
assert_series_equal(a, expected)
54
assert_series_equal(result, expected)
55
assert a.n_chunks() == 1
56
57
58
def test_extend_sliced_12968() -> None:
59
assert pl.Series(["a", "b"]).slice(0, 1).extend(pl.Series(["c"])).to_list() == [
60
"a",
61
"c",
62
]
63
64