Skip to content

Commit

Permalink
fix: Full null on dyn int (pola-rs#16679)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored and Wouittone committed Jun 22, 2024
1 parent 13b54c9 commit 92928fd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/polars-core/src/datatypes/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ pub enum UnknownKind {
Any,
}

impl UnknownKind {
pub fn materialize(&self) -> Option<DataType> {
let dtype = match self {
UnknownKind::Int(v) => materialize_dyn_int(*v).dtype(),
UnknownKind::Float => DataType::Float64,
UnknownKind::Str => DataType::String,
UnknownKind::Any => return None,
};
Some(dtype)
}
}

#[derive(Clone, Debug)]
pub enum DataType {
Boolean,
Expand Down
4 changes: 4 additions & 0 deletions crates/polars-core/src/series/ops/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ impl Series {
StructChunked::new(name, &fields).unwrap().into_series()
},
DataType::Null => Series::new_null(name, size),
DataType::Unknown(kind) => {
let dtype = kind.materialize().expect("expected known type");
Series::full_null(name, size, &dtype)
},
_ => {
macro_rules! primitive {
($type:ty) => {{
Expand Down
5 changes: 5 additions & 0 deletions py-polars/tests/unit/test_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,8 @@ def test_empty_is_in() -> None:
@pytest.mark.parametrize("method", ["drop_nulls", "unique"])
def test_empty_to_empty(method: str) -> None:
assert getattr(pl.DataFrame(), method)().shape == (0, 0)


def test_empty_shift_over_16676() -> None:
df = pl.DataFrame({"a": [], "b": []})
assert df.with_columns(pl.col("a").shift(fill_value=0).over("b")).shape == (0, 2)

0 comments on commit 92928fd

Please sign in to comment.