Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
martindurant committed Dec 22, 2023
1 parent 1a6747c commit c6b0677
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/awkward_pandas/polars.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def __dir__(self) -> Iterable[str]:
def apply(self, fn: Callable) -> pl.DataFrame:
"""Perform function on all the values of the series"""
out = fn(self.array)
result = pl.from_arrow(ak.to_arrow(out, extensionarray=False))
return result
return ak_to_polars(out)

def __getitem__(self, item):
# scalars?
out = self.array.__getitem__(item)
result = pl.from_arrow(ak.to_arrow(out, extensionarray=False))
result = ak_to_polars(out)
return result

@property
Expand Down Expand Up @@ -55,10 +55,13 @@ def f(*others, **kwargs):

ak_arr = func(self.array, *others, **kwargs)
if isinstance(ak_arr, ak.Array):
return pl.from_arrow(ak.to_arrow(ak_arr, extensionarray=False))
return ak_to_polars(ak_arr)
return ak_arr

else:
raise AttributeError

raise AttributeError(item)
return f


def ak_to_polars(arr: ak.Array) -> pl.DataFrame | pl.Series:
return pl.from_arrow(ak.to_arrow(arr, extensionarray=False))

0 comments on commit c6b0677

Please sign in to comment.