Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable mixins behavior #1437

Merged
merged 3 commits into from
Apr 22, 2022
Merged

Enable mixins behavior #1437

merged 3 commits into from
Apr 22, 2022

Conversation

ioanaif
Copy link
Collaborator

@ioanaif ioanaif commented Apr 21, 2022

No description provided.

@codecov
Copy link

codecov bot commented Apr 21, 2022

Codecov Report

Merging #1437 (702ee34) into main (edfce38) will decrease coverage by 0.08%.
The diff coverage is 60.83%.

Impacted Files Coverage Δ
src/awkward/_v2/_connect/cuda/__init__.py 0.00% <0.00%> (ø)
src/awkward/_v2/_connect/jax/__init__.py 0.00% <0.00%> (ø)
src/awkward/_v2/contents/recordarray.py 82.26% <ø> (+0.76%) ⬆️
src/awkward/_v2/contents/unionarray.py 86.50% <ø> (ø)
src/awkward/_v2/operations/convert/ak_from_cupy.py 50.00% <0.00%> (+23.33%) ⬆️
src/awkward/_v2/operations/convert/ak_from_iter.py 93.75% <ø> (ø)
src/awkward/_v2/operations/convert/ak_from_jax.py 50.00% <0.00%> (-25.00%) ⬇️
...wkward/_v2/operations/convert/ak_to_arrow_table.py 100.00% <ø> (ø)
src/awkward/_v2/operations/convert/ak_to_cupy.py 33.33% <0.00%> (+23.95%) ⬆️
src/awkward/_v2/operations/convert/ak_to_jax.py 33.33% <0.00%> (-41.67%) ⬇️
... and 74 more

@ioanaif ioanaif marked this pull request as ready for review April 21, 2022 20:24
@ioanaif ioanaif requested a review from jpivarski April 22, 2022 07:04
Copy link
Member

@jpivarski jpivarski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I found an issue, but it's not an issue with this PR.

self._fields_identifer(where),
self._fields_identifier(where),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

Comment on lines 514 to -517
if not isstr(custom):
custom = layout.parameter("__record__")
if not isstr(custom):
custom = layout.purelist_parameter("__record__")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was it once necessary to descend through lists to identify a record but now isn't?

I saw that there are some arrays of lists of records in the tests, which I'd think this is relevant for. If any of those tests override ufuncs, which I think they don't.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I tried it, and apparently this is fixing what I was thinking about, rather than breaking it.

In main:

>>> ak._v2.behavior[np.absolute, "Point"] = lambda data: np.sqrt(data.x**2 + data.y**2)
>>> array = ak._v2.Array([{"x": 1.0, "y": 1.1}, {"x": 2.0, "y": 2.2}], with_name="Point")
>>> np.absolute(array)
<Array [1.49, 2.97] type='2 * float64'>
>>> array2 = ak._v2.Array([[{"x": 1.0, "y": 1.1}], [], [{"x": 2.0, "y": 2.2}]], with_name="Point")
>>> np.absolute(array2)
Traceback (most recent call last):
...
  File "/home/jpivarski/mambaforge/lib/python3.9/site-packages/awkward/_v2/_connect/numpy.py", line 109, in _array_ufunc_adjust_apply
    out = apply_ufunc(ufunc, method, nextinputs, kwargs)
TypeError: <lambda>() takes 1 positional argument but 4 were given

but in this branch:

>>> ak._v2.behavior[np.absolute, "Point"] = lambda data: np.sqrt(data.x**2 + data.y**2)
>>> array = ak._v2.Array([{"x": 1.0, "y": 1.1}, {"x": 2.0, "y": 2.2}], with_name="Point")
>>> np.absolute(array)
<Array [1.49, 2.97] type='2 * float64'>
>>> array2 = ak._v2.Array([[{"x": 1.0, "y": 1.1}], [], [{"x": 2.0, "y": 2.2}]], with_name="Point")
>>> np.absolute(array2)
<Array [[1.49], [], [2.97]] type='3 * var * float64'>

So this must be the right thing to do. The thing I was worried about was it not finding the overloaded record when it's buried inside of a list like that.

But, uh-oh: there's another problem—if the array does not have the with_name="Point", ufuncs are not supposed to work on records. In v1:

>>> array = ak.Array([{"x": 1.0, "y": 1.1}, {"x": 2.0, "y": 2.2}])
>>> np.absolute(array)
Traceback (most recent call last):
...
  File "/home/jpivarski/irishep/awkward-1.0/awkward/_util.py", line 1058, in apply
    raise ValueError(
ValueError: cannot broadcast records in this type of operation

(https://github.com/scikit-hep/awkward-1.0/blob/1.9.0rc2/src/awkward/_util.py#L1060)

(that's good), but in v2:

>>> array = ak._v2.Array([{"x": 1.0, "y": 1.1}, {"x": 2.0, "y": 2.2}])
>>> np.absolute(array)
<Array [{x: 1, y: 1.1}, {x: 2, ...}] type='2 * {x: float64, y: float64}'>

(that's bad). But I tried this in main as well as this branch and it's the same in both, so it's unrelated to this change. I'll make it a new issue and prioritize it.

@jpivarski jpivarski merged commit 779819e into main Apr 22, 2022
@jpivarski jpivarski deleted the ioanaif/enable-mixins-behavior branch April 22, 2022 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants