Skip to content

Commit

Permalink
Use length instead of explicit None values
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Jun 26, 2024
1 parent 11055c6 commit 389ccfc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
5 changes: 1 addition & 4 deletions crates/polars-core/src/serde/chunked_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,7 @@ impl Serialize for NullChunked {
let mut state = serializer.serialize_map(Some(3))?;
state.serialize_entry("name", self.name())?;
state.serialize_entry("datatype", self.dtype())?;
state.serialize_entry(
"values",
&IterSer::new(std::iter::repeat(None::<()>).take(self.len())),
)?;
state.serialize_entry("values", &IterSer::new(std::iter::once(self.len())))?;
state.end()
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/polars-core/src/serde/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ impl<'de> Deserialize<'de> for Series {
Ok(Series::new(&name, values).cast(&dt).unwrap())
},
DataType::Null => {
let values: Vec<Option<Cow<[usize]>>> = map.next_value()?;
let len = values.len();
Ok(Series::new_null(&name, len))
let values: Vec<usize> = map.next_value()?;
let len = values.first().unwrap();
Ok(Series::new_null(&name, *len))
},
dt => {
panic!("{dt:?} dtype deserialization not yet implemented")
Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/unit/dataframe/test_serde.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_df_serde_float_inf_nan() -> None:


def test_df_serde_null() -> None:
df = pl.DataFrame({"a": [None, None]})
df = pl.DataFrame({"a": [None, None]}, schema={"a": pl.Null})
ser = df.serialize()
result = pl.DataFrame.deserialize(io.StringIO(ser))
assert_frame_equal(result, df)
Expand Down

0 comments on commit 389ccfc

Please sign in to comment.