Skip to content

Commit

Permalink
fix(rust, python): respect dtype in anonymous list builder in case of… (
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Apr 22, 2023
1 parent ec107a2 commit 77a6465
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 10 additions & 2 deletions polars/polars-arrow/src/array/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,16 @@ impl<'a> AnonymousBuilder<'a> {
let offsets = unsafe { Offsets::new_unchecked(self.offsets) };
let (inner_dtype, values) = if self.arrays.is_empty() {
let len = *offsets.last() as usize;
let values = NullArray::new(DataType::Null, len).boxed();
(DataType::Null, values)
match inner_dtype {
None => {
let values = NullArray::new(DataType::Null, len).boxed();
(DataType::Null, values)
}
Some(inner_dtype) => {
let values = new_null_array(inner_dtype.clone(), len);
(inner_dtype.clone(), values)
}
}
} else {
let inner_dtype = inner_dtype.unwrap_or_else(|| self.arrays[0].data_type());

Expand Down
7 changes: 7 additions & 0 deletions py-polars/tests/unit/datatypes/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,13 @@ def test_list_new_from_index_logical() -> None:
assert s.dtype == pl.List(pl.Struct([pl.Field("a", pl.Date)]))
assert s.to_list() == [[{"a": date(2001, 1, 1)}]]

# empty new_from_index # 8420
dtype = pl.List(pl.Struct({"c": pl.Boolean}))
s = pl.Series("b", values=[[]], dtype=dtype)
s = s.new_from_index(0, 2)
assert s.dtype == dtype
assert s.to_list() == [[], []]


def test_list_recursive_time_unit_cast() -> None:
values = [[datetime(2000, 1, 1, 0, 0, 0)]]
Expand Down

0 comments on commit 77a6465

Please sign in to comment.