fix: remove python roundtrip in list ser/de - #244
Conversation
|
|
||
| return target_cols | ||
|
|
||
| def _explode_list(flattened: list[Any], orig_lengths: list[int]) -> list[list | None]: |
There was a problem hiding this comment.
I think the action here is closer to unflatten than to explode, but I'm happy to be corrected if that's not the case. Also, maybe "explode" is always the right term to use in the context of dataframes.
There was a problem hiding this comment.
Yep sorry "explode" is definitely not the right term here, that would be going in the other direction to a "long format".
"Implode" is technically correct either since that operates on a typically refers to aggregating over a column. "Unflatten" is probably the most precise term for this operation.
| dtype=pl.Object, | ||
| ) | ||
| lengths = s.list.len().to_list() | ||
| flat = s.explode(empty_as_null=False) |
There was a problem hiding this comment.
is flat the right var name here? (exploded != flat, right?)
| flat = s.explode(empty_as_null=False) | |
| exploded = s.explode(empty_as_null=False) |
There was a problem hiding this comment.
Yep agree. The intention is that the result will be flat since we don't expect people to have nested lists of GK objects. I'll document that expectation somewhere as well.
(Nested lists of standard data types are supported in polars)
|
Quick note on the serialization/deserialization paths for None values,
|
Previous list serialization/deserialization paths treated used each cell as a separate call to the appropriate function. Since the serde functions took polars series as input, this meant every cell was converted from
list -> pl.Series -> list. The time taken for this conversion is mostly inconsequential, but adds up over larger dataframes.The new implementation flattens a column (of list of GK objects/structs) into a single list, converts that into a
pl.Series, and runs that through the appropriate function before reconstructing the correct list lengths.Empirically, this speeds up the serde paths by around 2-3 times:
Also makes polars options explicit when exploding lists of objects and correct
Noneobject serde.