polars
polars copied to clipboard
feat(python,rust): Implement `pl.unnest` Expr
This PR introduces a pl.unnest function for accessing nested struct columns, based on conversations in #3123. The goal is to allow a JSONPath-like string to index single or multiple columns that are nested at arbitrary depth.
- [ ] Implement the actual path and unnesting logic
- [ ] Add examples to the docs
- [ ] Add tests
The current implementation connects all the features end-to-end, but implements a very basic conversion from path to columns that needs to be replaced. You can try it out with:
import polars as pl
df = pl.DataFrame({'b': [1, 2, 3], 'c': [0, 0, 0]}).to_struct('a').to_frame()
df.select(pl.unnest('a.b'))
I'm planning to revisit this PR after solving an issue in json_path_match, which has some conceptual overlaps. https://github.com/pola-rs/polars/issues/3373
I am closing this as the last update was over a year ago. Feel free to rebase and reopen this if you want to finish the PR.