Skip to content

Commit

Permalink
explode series after slide fast path (#3467)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed May 22, 2022
1 parent 5c128e3 commit 4a39576
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion polars/polars-core/src/frame/explode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion py-polars/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub fn get_either_file(py_f: PyObject, truncate: bool) -> PyResult<EitherRustPyt
} else {
match File::open(str_slice) {
Ok(file) => BufReader::new(file),
Err(e) => {
Err(_e) => {
return Err(PyErr::new::<PyFileNotFoundError, _>(format!(
"No such file or directory: {}",
str_slice
Expand Down
5 changes: 5 additions & 0 deletions py-polars/tests/test_explode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit 4a39576

Please sign in to comment.