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: don't try to re-wrap array_function overload results #2079

Merged
merged 3 commits into from
Jan 6, 2023

Conversation

agoose77
Copy link
Collaborator

@agoose77 agoose77 commented Jan 6, 2023

Our integration with NumPy's array function mechanism means that users can in some cases invoke NumPy-only functions on Awkward Arrays (if they're rectilinear). However, our existing support for this mechanism is breaking Awkward overloads such as ak.broadcast_arrays, because it assumes that the result should be a layout.

In the long run, we could apply an inverse _to_rectilinear transform to recover high-level ak.Array/ak.Records, but in this instance, I think the solution is even more clear cut.

If Awkward has an overload for an array function, then it should already be returning high-level objects. Therefore, we don't need to re-wrap the result. This PR applies such a fix, which means that any NumPy-only overloads that return non-arrays will still need a fix. However, this is a simple first step.

Fixes #2078

@codecov
Copy link

codecov bot commented Jan 6, 2023

Codecov Report

Merging #2079 (135f2e6) into main (26f9481) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
Impacted Files Coverage Δ
src/awkward/_connect/numpy.py 67.28% <100.00%> (+0.16%) ⬆️

@agoose77 agoose77 temporarily deployed to docs-preview January 6, 2023 01:27 — with GitHub Actions Inactive
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.

Okay, got it. This is looking good so far. I'll take another look when it's out of draft mode (remind me).

Nope, it is out of draft mode! (I was thinking of a different PR.) I did take a good look at this and it makes sense. It is mergeable as-is, with the understanding that it's only for a simple case and that more is needed to solve the problem overall.

@agoose77
Copy link
Collaborator Author

agoose77 commented Jan 6, 2023

Right. It doesn't try to solve the NumPy side of things, e.g. if we didn't define ak.broadcast_arrays, the result of calling np.broadcast_arrays would fail in the same manner.

We could be smarter there, but I also think there comes a point where we need to write an overload to handle the dynamicism of the NumPy API. That said, exploring returned tuples / lists and interpreting np.ndarray is definitely possible. Thankfully, we would still want this PR if we do decide to go that extra step in the future.

@agoose77 agoose77 merged commit 7823a2b into main Jan 6, 2023
@agoose77 agoose77 deleted the agoose77/fix-array-function-overloaded branch January 6, 2023 08:03
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.

np.broadcast_arrays array function overload has unknown result type
2 participants