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

Fix: ufuncs on records should not be allowed unless overridden #1559

Merged
merged 6 commits into from
Jul 28, 2022

Conversation

ioanaif
Copy link
Collaborator

@ioanaif ioanaif commented Jul 21, 2022

@codecov
Copy link

codecov bot commented Jul 21, 2022

Codecov Report

Merging #1559 (55eac8a) into main (78a6535) will increase coverage by 0.26%.
The diff coverage is 75.69%.

Impacted Files Coverage Δ
src/awkward/_v2/_connect/numpy.py 63.50% <ø> (ø)
src/awkward/_v2/contents/bitmaskedarray.py 66.41% <ø> (-0.76%) ⬇️
src/awkward/_v2/contents/bytemaskedarray.py 88.82% <ø> (-0.28%) ⬇️
src/awkward/_v2/contents/emptyarray.py 71.66% <ø> (ø)
src/awkward/_v2/contents/indexedarray.py 73.83% <ø> (ø)
src/awkward/_v2/contents/listarray.py 91.79% <ø> (ø)
src/awkward/_v2/contents/listoffsetarray.py 81.85% <ø> (ø)
src/awkward/_v2/contents/numpyarray.py 87.34% <ø> (ø)
src/awkward/_v2/contents/regulararray.py 85.48% <ø> (-0.21%) ⬇️
src/awkward/_v2/contents/unionarray.py 86.27% <ø> (ø)
... and 49 more

@ioanaif
Copy link
Collaborator Author

ioanaif commented Jul 22, 2022

Now that ufuncs are no longer allowed for records in v2, test 0355-mixins fails withError details: cannot broadcast records in absolute @jpivarski

@jpivarski
Copy link
Member

While it's possible that we'll find some tests that assume you can apply ufuncs (like np.abs) to generic records and those tests have to be changed or removed, this particular test should still work.

In the definition of Point, a method was defined for np.abs:

@ak.mixin_class_method(np.abs)
def point_abs(self):
return np.sqrt(self.x**2 + self.y**2)

The rule should be that records can't be used in ufuncs unless a method has been defined for that particular ufunc, as is the case here. That's what broadcast_and_apply does; recursively_apply should follow the same rule. (That is, np.add(record, record) should fail if record does not have an implementation of np.add, but it should use that implementation if it does.)

@ioanaif ioanaif requested a review from jpivarski July 25, 2022 19:32
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.

Yes! recursively_apply should be just like broadcast_and_apply in requiring behavior and not allowing records unless the records are overloaded.

Just need a test to be sure that np.absolute will work if it is overloaded (like np.add).

Once that test has been added and it passes, go ahead and merge.

tests/v2/test_1559_fix_ufuncs_records_1439.py Outdated Show resolved Hide resolved
@ioanaif ioanaif merged commit 3290192 into main Jul 28, 2022
@ioanaif ioanaif deleted the ioanaif/fix-ufuncs-records-1439 branch July 28, 2022 15:37
ManasviGoyal pushed a commit that referenced this pull request Aug 6, 2022
* Added  to recursively_apply for ufuncs on records

* Renamed test to match PR nr

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Forward behavior in  to check for overriden ufuncs

* Added test for overloaded absolutefunction

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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