polars icon indicating copy to clipboard operation
polars copied to clipboard

feat(python,rust): Implement `pl.unnest` Expr

Open cjermain opened this issue 3 years ago • 2 comments

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

cjermain avatar Apr 17 '22 00:04 cjermain

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'))

cjermain avatar Apr 17 '22 03:04 cjermain

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

cjermain avatar May 12 '22 01:05 cjermain

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.

stinodego avatar Aug 09 '23 19:08 stinodego