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

ndarray.reshape prototype mismatch #556

Open
kyleaoman opened this issue Jan 30, 2025 · 3 comments
Open

ndarray.reshape prototype mismatch #556

kyleaoman opened this issue Jan 30, 2025 · 3 comments

Comments

@kyleaoman
Copy link
Contributor

As of numpy 2.1 the ndarray.reshape function has a new keyword argument copy (https://numpy.org/doc/2.1/reference/generated/numpy.ndarray.reshape.html) that is not reflected in the unyt_quantity implementation:

def reshape(self, *shape, order="C"):

@neutrinoceros
Copy link
Member

Hum, this seems less trivial to fix than I naively assumed. The root issue is that in order to properly support the copy kwarg, we should also add it to unyt_quantity.__new__ and unyt_array.__new__, which in turn require that it is available on np.asarray, where it was only added in numpy 2.0 ...
I think we should support this, but trying to do it while we still support numpy 1.x is more effort than I can spare at the moment, so I'm tempted to post-pone it to after we drop numpy 1.x (which we should probably not do until at least March 2026). Of course, if anyone wants to work on this before that, I'll be happy to review a patch.

Is this blocking your work in any way ?

@kyleaoman
Copy link
Contributor Author

I had an attempt at a fix, too, and likewise quickly discovered that various things were breaking far away and left it before getting too sidetracked. This doesn't block anything that I've discovered so far - I just need to mimic the older-style prototype on my side, but it's an obscure enough feature that I don't think it matters for anything user-facing. The copy kwarg does seem like something that might get used internally in numpy in the future, so agree it should be supported eventually, but not urgently.

@kyleaoman
Copy link
Contributor Author

Actually just got more clever with decorators and now don't need any special handling on my end, I'll just inherit whatever improvements happen in unyt now :)

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

No branches or pull requests

2 participants