Skip to content

Commit

Permalink
test: remove ak.behavior usage in tests (#1716)
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 authored Sep 26, 2022
1 parent 472d26a commit 3008f23
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
11 changes: 8 additions & 3 deletions tests/test_0355-mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@


def test_make_mixins():
@ak.behaviors.mixins.mixin_class(ak.behavior)
behavior = {}

@ak.behaviors.mixins.mixin_class(behavior)
class Point:
def distance(self, other):
return np.sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2)
Expand All @@ -29,7 +31,7 @@ def point_add(self, other):
with_name="Point",
)

@ak.behaviors.mixins.mixin_class(ak.behavior)
@ak.behaviors.mixins.mixin_class(behavior)
class WeightedPoint(Point):
@ak.behaviors.mixins.mixin_class_method(np.equal, {"WeightedPoint"})
def weighted_equal(self, other):
Expand All @@ -54,6 +56,7 @@ def weighted_add(self, other):
[{"x": 4, "y": 4.4}, {"x": 5, "y": 5.5}],
],
with_name="Point",
behavior=behavior,
)
two = ak.Array(
[
Expand All @@ -62,16 +65,18 @@ def weighted_add(self, other):
[{"x": 3.9, "y": 4}, {"x": 5, "y": 5.5}],
],
with_name="Point",
behavior=behavior,
)
wone = ak.Array(
ak.operations.with_field(one, abs(one), "weight"),
with_name="WeightedPoint",
behavior=behavior,
)
wtwo = ak.Array(
ak.operations.with_field(two, abs(two), "weight"),
with_name="WeightedPoint",
behavior=behavior,
)

assert to_list(one + wone) == [
[{"x": 2, "y": 2.2}, {"x": 4, "y": 4.4}, {"x": 6, "y": 6.6}],
[],
Expand Down
6 changes: 4 additions & 2 deletions tests/test_0504-block-ufuncs-for-strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ def _apply_ufunc(ufunc, method, inputs, kwargs):

return getattr(ufunc, method)(*nextinputs, **kwargs)

ak.behavior[np.ufunc, "categorical"] = _apply_ufunc
behavior = {}
behavior[np.ufunc, "categorical"] = _apply_ufunc

array = ak.highlevel.Array(
ak.contents.IndexedArray(
ak.index.Index64(np.array([0, 1, 2, 1, 3, 1, 4])),
ak.contents.NumpyArray(np.array([321, 1.1, 123, 999, 2])),
parameters={"__array__": "categorical"},
)
),
behavior=behavior,
)
assert to_list(array * 10) == [3210, 11, 1230, 11, 9990, 11, 20]

Expand Down
8 changes: 6 additions & 2 deletions tests/test_0930-bug-in-unionarray-purelist_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@


def test():
@ak.behaviors.mixins.mixin_class(ak.behavior)
behavior = {}

@ak.behaviors.mixins.mixin_class(behavior)
class Blah:
@property
def blah(self):
Expand All @@ -18,6 +20,8 @@ def blah(self):

a2 = a[a.x % 2 == 0]
b2 = b[b.x % 2 == 0]
c2 = ak.operations.with_name(ak.operations.concatenate([a2, b2], axis=1), "Blah")
c2 = ak.operations.with_name(
ak.operations.concatenate([a2, b2], axis=1), "Blah", behavior=behavior
)

assert c2.blah.tolist() == [[2, -2], [-4]]

0 comments on commit 3008f23

Please sign in to comment.