Skip to content

Commit

Permalink
Merge pull request #228 from lgray/behavior_tweak
Browse files Browse the repository at this point in the history
Substitute in self for _dask_array_ when it is not specified
  • Loading branch information
martindurant authored Apr 14, 2023
2 parents 4f1f5bd + e25b58c commit e8d8f32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/dask_awkward/lib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,8 @@ def _call_behavior_method(self, method_name: str, *args: Any, **kwargs: Any) ->
themethod = getattr(self._meta, method_name)
thesig = inspect.signature(themethod)
if "_dask_array_" in thesig.parameters:
if "_dask_array_" not in kwargs:
kwargs["_dask_array_"] = self
return themethod(*args, **kwargs)
return self.map_partitions(
_BehaviorMethodFn(method_name, **kwargs),
Expand Down
11 changes: 11 additions & 0 deletions tests/test_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ def x2(self):
def point_abs(self):
return np.sqrt(self.x**2 + self.y**2)

@property
def non_dask_property(self, _dask_array_=None):
return "this is a non-dask property"

def non_dask_method(self, _dask_array_=None):
return _dask_array_


def test_distance_behavior(
daa_p1: dak.Array,
Expand All @@ -45,6 +52,10 @@ def test_property_behavior(daa_p1: dak.Array, caa_p1: ak.Array) -> None:

assert daa.behavior == caa.behavior

assert daa.non_dask_property == caa.non_dask_property

assert repr(daa.non_dask_method()) == repr(daa)


def test_nonexistent_behavior(daa_p1: dak.Array, daa_p2: dak.Array) -> None:
daa1 = dak.with_name(daa_p1["points"], "Point", behavior=behaviors)
Expand Down

0 comments on commit e8d8f32

Please sign in to comment.