Skip to content

Commit

Permalink
fix: Update offsets of null value correctly for all `from_iter_xxx_tr…
Browse files Browse the repository at this point in the history
…usted_len` (#13132)
  • Loading branch information
reswqa committed Dec 19, 2023
1 parent 968ba48 commit 1e28874
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions crates/polars-arrow/src/legacy/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ macro_rules! iter_to_values {
},
None => {
$validity.push(false);
$offsets.push($length_so_far);
None
},
})
Expand Down Expand Up @@ -131,6 +132,7 @@ pub trait ListFromIter {
},
None => {
validity.push(false);
offsets.push(length_so_far);
None
},
})
Expand Down
17 changes: 14 additions & 3 deletions py-polars/tests/unit/functions/test_repeat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from datetime import date, datetime, time, timedelta
from typing import Any

Expand Down Expand Up @@ -156,8 +158,17 @@ def test_repeat_by_logical_dtype() -> None:
assert_frame_equal(out, expected_df)


def test_repeat_by_none_13053() -> None:
df = pl.DataFrame({"x": ["a", "b", None], "by": [2, None, 3]})
@pytest.mark.parametrize(
("data", "expected_data"),
[
(["a", "b", None], [["a", "a"], None, [None, None, None]]),
([1, 2, None], [[1, 1], None, [None, None, None]]),
([1.1, 2.2, None], [[1.1, 1.1], None, [None, None, None]]),
([True, False, None], [[True, True], None, [None, None, None]]),
],
)
def test_repeat_by_none_13053(data: list[Any], expected_data: list[list[Any]]) -> None:
df = pl.DataFrame({"x": data, "by": [2, None, 3]})
res = df.select(repeat=pl.col("x").repeat_by("by"))
expected = pl.Series("repeat", [["a", "a"], None, [None, None, None]])
expected = pl.Series("repeat", expected_data)
assert_series_equal(res.to_series(), expected)

0 comments on commit 1e28874

Please sign in to comment.