Skip to content

Commit

Permalink
fix(rust): json_extract on empty series (pola-rs#9126)
Browse files Browse the repository at this point in the history
  • Loading branch information
josh authored and c-peters committed Jul 14, 2023
1 parent 0b55d62 commit 2d06f37
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion polars/polars-json/src/ndjson/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ pub fn deserialize_iter<'a>(
buf.push_str(row);
buf.push(',')
}
let _ = buf.pop();
if buf.len() > 1 {
let _ = buf.pop();
}
buf.push(']');
let slice = unsafe { buf.as_bytes_mut() };
let out = simd_json::to_borrowed_value(slice)
Expand Down
5 changes: 5 additions & 0 deletions py-polars/tests/unit/namespaces/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ def test_json_extract_series() -> None:
dtype2 = pl.Struct([pl.Field("a", pl.Int64)])
assert_series_equal(s.str.json_extract(dtype2), expected)

s = pl.Series([], dtype=pl.Utf8)
expected = pl.Series([], dtype=pl.List(pl.Int64))
dtype = pl.List(pl.Int64)
assert_series_equal(s.str.json_extract(dtype), expected)


def test_json_extract_lazy_expr() -> None:
dtype = pl.Struct([pl.Field("a", pl.Int64), pl.Field("b", pl.Boolean)])
Expand Down

0 comments on commit 2d06f37

Please sign in to comment.