diff --git a/crates/polars-core/src/datatypes/dtype.rs b/crates/polars-core/src/datatypes/dtype.rs index f7137330eb5d7..79b1c8f5145ba 100644 --- a/crates/polars-core/src/datatypes/dtype.rs +++ b/crates/polars-core/src/datatypes/dtype.rs @@ -28,6 +28,18 @@ pub enum UnknownKind { Any, } +impl UnknownKind { + pub fn materialize(&self) -> Option { + 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, diff --git a/crates/polars-core/src/series/ops/null.rs b/crates/polars-core/src/series/ops/null.rs index 42d200ddcb566..53ea772c62ada 100644 --- a/crates/polars-core/src/series/ops/null.rs +++ b/crates/polars-core/src/series/ops/null.rs @@ -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) => {{ diff --git a/py-polars/tests/unit/test_empty.py b/py-polars/tests/unit/test_empty.py index acf650185c646..69f487061630e 100644 --- a/py-polars/tests/unit/test_empty.py +++ b/py-polars/tests/unit/test_empty.py @@ -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)