Skip to content

Commit

Permalink
string exception
Browse files Browse the repository at this point in the history
  • Loading branch information
martindurant committed Nov 11, 2024
1 parent 6cc2764 commit f43f1ac
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/akimbo/apply_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def run_with_transform(
**kw,
) -> ak.Array:
def func(layout, **kwargs):
from akimbo.utils import match_string

if not isinstance(layout, tuple):
layout = (layout,)
if all(match(lay, **(match_kwargs or {})) for lay in layout):
Expand All @@ -57,6 +59,9 @@ def func(layout, **kwargs):
return out.layout
else:
return out
if match_string(*layout):
# non-string op may fail to descend into string
return layout[0]

return ak.transform(func, arr, *others, allow_records=True)

Expand Down
5 changes: 1 addition & 4 deletions src/akimbo/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

from akimbo.apply_tree import dec
from akimbo.mixin import Accessor


def match_string(*layout):
return layout[0].is_list and layout[0].parameter("__array__") == "string"
from akimbo.utils import match_string


def _encode(layout):
Expand Down
6 changes: 6 additions & 0 deletions src/akimbo/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import awkward as ak


Expand Down Expand Up @@ -34,3 +36,7 @@ def to_ak_layout(ar):
return ar
else:
return ak.Array(ak.to_layout(ar))


def match_string(*layout):
return layout[0].is_list and layout[0].parameter("__array__") == "string"
1 change: 1 addition & 0 deletions tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def test_mixed_ufunc():
df2 = df.ak == df.ak
expected = [[True, True, True], [True, True], [True]]
assert df2["b"].tolist() == expected
assert df2["a"].tolist() == df["a"].tolist()


def test_to_autoarrow():
Expand Down

0 comments on commit f43f1ac

Please sign in to comment.