Skip to content

Commit

Permalink
fix[rust]: fix Series::full_null for list dtype (#4407)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Aug 14, 2022
1 parent 0d503d9 commit d1dc004
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 0 additions & 1 deletion polars/polars-core/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ impl DataFrame {
/// Ensure all the chunks in the DataFrame are aligned.
pub fn rechunk(&mut self) -> &mut Self {
if self.should_rechunk() {
debug_assert!(!self.columns.iter().map(|s| s.n_chunks()).all_equal());
self.as_single_chunk_par()
} else {
self
Expand Down
8 changes: 3 additions & 5 deletions polars/polars-core/src/series/ops/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ use crate::prelude::*;

impl Series {
pub fn full_null(name: &str, size: usize, dtype: &DataType) -> Self {
if let DataType::List(dtype) = dtype {
let val = Series::full_null("", 0, dtype);
let avs = [AnyValue::List(val)];
return Series::new(name, avs.as_ref());
}
// match the logical types and create them
match dtype {
DataType::List(inner_dtype) => {
ListChunked::full_null_with_dtype(name, size, inner_dtype).into_series()
}
#[cfg(feature = "dtype-categorical")]
DataType::Categorical(_) => CategoricalChunked::full_null(name, size).into_series(),
#[cfg(feature = "dtype-date")]
Expand Down
11 changes: 11 additions & 0 deletions py-polars/tests/test_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,14 @@ def test_arr_contains_categorical() -> None:
assert df_groups.filter(pl.col("str_list").arr.contains("C")).collect().to_dict(
False
) == {"group": [2], "str_list": [["A", "C"]]}


def test_list_diagonal_concat() -> None:
df1 = pl.DataFrame({"a": [1, 2]})

df2 = pl.DataFrame({"b": [[1]]})

assert pl.concat([df1, df2], how="diagonal").to_dict(False) == {
"a": [1, 2, None],
"b": [None, None, [1]],
}

0 comments on commit d1dc004

Please sign in to comment.