Skip to content

Commit

Permalink
list fast-explode should be off when add null to list
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Oct 15, 2021
1 parent 0599f60 commit 6bfbc56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github_changelog_generator
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
since-tag=py-polars-v0.8.18
since-tag=py-polars-v0.10.1
future-release=v0.10.1
base=py-polars/CHANGELOG.md
output=AUTO_CHANGELOG.md
Expand Down
24 changes: 15 additions & 9 deletions polars/polars-core/src/chunked_array/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,6 @@ where
unsafe { values.extend_trusted_len_unchecked(iter) };
self.builder.try_push_valid().unwrap();
}

pub fn append_null(&mut self) {
self.builder.push_null();
}
}

impl<T> ListBuilderTrait for ListPrimitiveChunkedBuilder<T>
Expand All @@ -436,14 +432,13 @@ where
Some(s) => {
self.append_series(s);
}
None => {
self.builder.push_null();
}
None => self.append_null(),
}
}

#[inline]
fn append_null(&mut self) {
self.fast_explode = false;
self.builder.push_null();
}

Expand Down Expand Up @@ -519,13 +514,14 @@ impl ListBuilderTrait for ListUtf8ChunkedBuilder {
match opt_s {
Some(s) => self.append_series(s),
None => {
self.builder.push_null();
self.append_null();
}
}
}

#[inline]
fn append_null(&mut self) {
self.fast_explode = false;
self.builder.push_null();
}

Expand Down Expand Up @@ -583,13 +579,14 @@ impl ListBuilderTrait for ListBooleanChunkedBuilder {
match opt_s {
Some(s) => self.append_series(s),
None => {
self.builder.push_null();
self.append_null();
}
}
}

#[inline]
fn append_null(&mut self) {
self.fast_explode = false;
self.builder.push_null();
}

Expand Down Expand Up @@ -684,6 +681,15 @@ mod test {
let out = [&s1, &s2].iter().copied().collect::<ListChunked>();
assert_eq!(out.get(0).unwrap().len(), 6);
assert_eq!(out.get(1).unwrap().len(), 3);

let mut builder = ListPrimitiveChunkedBuilder::<Int32Type>::new("a", 10, 5);
builder.append_series(&s1);
builder.append_null();

let out = builder.finish();
let out = out.explode().unwrap();
assert_eq!(out.len(), 7);
assert_eq!(out.get(6), AnyValue::Null);
}

#[test]
Expand Down

0 comments on commit 6bfbc56

Please sign in to comment.