Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename un/merge, add unexplode #84

Merged
merged 2 commits into from
Nov 13, 2024
Merged

Conversation

martindurant
Copy link
Member

No description provided.

out = {k: self.to_output(arr[k]) for k in arr.fields}
return self.dataframe_type(out)

def group_lists(self, *cols, outname="grouped"):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpivarski : my implementation of the opposite of explode. We could still call this "unexplode", maybe.

In [1]: import polars as pl

In [2]: import akimbo.polars

In [3]: df = pl.DataFrame({"x": [1, 1, 1, 2, 1, 3, 3, 1], 'y':  [1, 1, 1, 2, 1, 3, 3, 1], 'z':  [1, 1, 1, 2, 1, 3, 3, 2]})

In [4]: df.ak.group_lists("x")
Out[4]:
shape: (3, 2)
┌─────┬─────────────────────────┐
│ x   ┆ grouped                 │
│ --- ┆ ---                     │
│ i64 ┆ list[struct[2]]         │
╞═════╪═════════════════════════╡
│ 1   ┆ [{1,1}, {1,1}, … {1,2}] │
│ 2   ┆ [{2,2}]                 │
│ 3   ┆ [{3,3}, {3,3}]          │
└─────┴─────────────────────────┘

In [5]: df.ak.group_lists("x", "y")
Out[5]:
shape: (3, 3)
┌─────┬─────┬───────────────────┐
│ x   ┆ y   ┆ grouped           │
│ --- ┆ --- ┆ ---               │
│ i64 ┆ i64 ┆ list[struct[1]]   │
╞═════╪═════╪═══════════════════╡
│ 1   ┆ 1   ┆ [{1}, {1}, … {2}] │
│ 2   ┆ 2   ┆ [{2}]             │
│ 3   ┆ 3   ┆ [{3}, {3}]        │
└─────┴─────┴───────────────────┘

@martindurant martindurant changed the title Rename un/merge, allow groupby listify Rename un/merge, add unexplode Nov 12, 2024
@martindurant
Copy link
Member Author

A better algorithm for unexplode can probably be found in awkward with or without numba - but this will do for now.

@martindurant martindurant merged commit 9f64d31 into intake:main Nov 13, 2024
12 checks passed
@martindurant martindurant deleted the repacking branch November 13, 2024 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant