From 4a3957682e87dc2af63b4197e9376ec557e6f36c Mon Sep 17 00:00:00 2001 From: Ritchie Vink Date: Sun, 22 May 2022 09:12:37 +0200 Subject: [PATCH] explode series after slide fast path (#3467) --- polars/polars-core/src/frame/explode.rs | 8 +++++++- py-polars/src/file.rs | 2 +- py-polars/tests/test_explode.py | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/polars/polars-core/src/frame/explode.rs b/polars/polars-core/src/frame/explode.rs index 4af4ba3fa8a3..4eeca11d43af 100644 --- a/polars/polars-core/src/frame/explode.rs +++ b/polars/polars-core/src/frame/explode.rs @@ -52,7 +52,13 @@ impl DataFrame { if !ca.can_fast_explode() { let (_, offsets) = get_exploded(col)?; if offsets.is_empty() { - return Ok(self.slice(0, 0)); + let mut out = self.slice(0, 0); + // still explode the columns to get the inner dtype + for col in &columns { + out.try_apply(col.name(), |s| s.explode())?; + } + + return Ok(out); } let mut mask = MutableBitmap::from_len_set(offsets.len() - 1); diff --git a/py-polars/src/file.rs b/py-polars/src/file.rs index 2d2858ba6a55..7455cf077034 100644 --- a/py-polars/src/file.rs +++ b/py-polars/src/file.rs @@ -212,7 +212,7 @@ pub fn get_either_file(py_f: PyObject, truncate: bool) -> PyResult BufReader::new(file), - Err(e) => { + Err(_e) => { return Err(PyErr::new::(format!( "No such file or directory: {}", str_slice diff --git a/py-polars/tests/test_explode.py b/py-polars/tests/test_explode.py index c6d0a789304e..a97b05e5da86 100644 --- a/py-polars/tests/test_explode.py +++ b/py-polars/tests/test_explode.py @@ -6,3 +6,8 @@ def test_explode_empty_df_3402() -> None: df = pl.DataFrame({"a": pa.array([], type=pa.large_list(pa.int32()))}) assert df.explode("a").dtypes == [pl.Int32] + + +def test_explode_empty_df_3460() -> None: + df = pl.DataFrame({"a": pa.array([[]], type=pa.large_list(pa.int32()))}) + assert df.explode("a").dtypes == [pl.Int32]