Skip to content

Commit

Permalink
Merge pull request #46 from douglasdavis/dev-explode
Browse files Browse the repository at this point in the history
feat: support `pd.Series.explode` with `ExtensionArray._explode` method
  • Loading branch information
martindurant authored Apr 16, 2024
2 parents f8bfbf3 + f723259 commit 36fc089
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/awkward_pandas/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ def _binop(self, other):
def _reduce(self, name: str, *, skipna: bool = True, axis=None, **kwargs):
return getattr(ak, name)(self._data, **kwargs)

def _explode(self):
nums = ak.num(self._data, axis=1)
nums_filled = ak.fill_none(nums, 0)
data = ak.where(nums_filled == 0, [[None]], self._data)
flat = ak.flatten(data)
arr = type(self)(flat)
return arr, ak.num(data, axis=1)

@property
def dtype(self) -> AwkwardDtype:
return self._dtype
Expand Down

0 comments on commit 36fc089

Please sign in to comment.