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

pint 0.24 / numpy 2.0 / python 3.9 issues #1974

Closed
keewis opened this issue Apr 29, 2024 · 19 comments · Fixed by #2019
Closed

pint 0.24 / numpy 2.0 / python 3.9 issues #1974

keewis opened this issue Apr 29, 2024 · 19 comments · Fixed by #2019

Comments

@keewis
Copy link
Contributor

keewis commented Apr 29, 2024

numpy>=2 will include a couple of breaking changes (to be released soonish), so it would be good to have a release of pint before that (I'd also love to have #1922 in a release, as it will fix some typing issues on python>=3.12)

Most of the urgent issues have already been fixed, the only thing left is #1971.

Other than that, __array__ has gained a optional copy kwarg which we should add (the version of __array__ without copy will cause a deprecation warning).

@cmutel
Copy link

cmutel commented May 12, 2024

In case anyone is having weird pint errors, or getting this error:

AttributeError: module 'numpy' has no attribute 'cumproduct'. Did you mean: 'cumprod'?

It's because you installed Numpy 2.0.RC1, which isn't yet supported.

@andrewgsavage
Copy link
Collaborator

I'm not sure how best to handle the __array__(copy) issue, we don't handle other optional args at present.
Other than that seems like 2.0 works now - I've added it to the matrix.(maybe too a bit too many places)

@andrewgsavage
Copy link
Collaborator

I think #1978 and #1960 could be merged if someone has the time to review.

Otherwise I think we're ready for a new release. Are there any other PRs that could be merged?

@keewis
Copy link
Contributor Author

keewis commented May 13, 2024

I would forward copy to the wrapped array, but in any case this is not urgent, since not having that argument will warn, not raise.

#1960 is a documentation-only PR (and from a quick glance I can't see anything wrong), so I think that PR is fine?

@dopplershift
Copy link
Contributor

dopplershift commented May 23, 2024

We're officially on the clock here, as NumPy 2.0 will release 16 June 2024.

It would be good to get some kind of release out the door since currently importing pint 0.23 with numpy 2 installed results in the AttributeError noted above.

I'm going to update on conda-forge to add a constraint for numpy < 2.

@jakirkham
Copy link

Do we know what issues still remain here?

Curious if anyone has tried to run the test suite with NumPy 2. If so, would be curious to know what that reveals

@andrewgsavage
Copy link
Collaborator

We're officially on the clock here, as NumPy 2.0 will release 16 June 2024.

I've released a pre-release. We've said to leave a week before full release so 0.24 can be released on the 8th.

@andrewgsavage
Copy link
Collaborator

0.24 released

@jakirkham
Copy link

Thanks Andrew! 🙏

@takluyver
Copy link
Contributor

takluyver commented Jun 17, 2024

If anyone else is still seeing the no attribute 'cumproduct' error, note that NumPy 2.0 is compatible with Python 3.9 and up, but Pint 0.24 requires Python 3.10 or above. So unfortunately, pip install numpy pint on Python 3.9 results in pint not being importable at all.

torrinba added a commit to gafusion/omas that referenced this issue Jun 17, 2024
This build is can no longer supported because of known issues with the pint module
hgrecco/pint#1974 (comment)
@slokhorst
Copy link

If anyone else is still seeing the no attribute 'cumproduct' error, note that NumPy 2.0 is compatible with Python 3.9 and up, but Pint 0.24 requires Python 3.10 or above. So unfortunately, pip install numpy pint on Python 3.9 results in pint not being importable at all.

This is an issue on Ubuntu 22.04.

Would it be possible to tag a new point release 0.23.1, with:
requires-python = ">=3.9" and numpy = "^1.23"?

@takluyver
Copy link
Contributor

Unfortunately I don't think that a new point release with metadata saying it needs numpy 1.x really solves this, because the dependency resolver is still free to pick pint 0.23, which appears to the tools to be compatible with numpy 2.0. In some cases it might decide to downgrade numpy instead, but not reliably.

Further complicating it, numpy is an optional dependency of pint. So if you pip install pint[numpy], pip would try to get compatible versions, but pip install pint numpy will install them as separate packages, ignoring any version constraints. There's no way to specify "pint doesn't require numpy, but numpy 2.0 breaks it" in packaging metadata.

The possible fixes I'm aware of here are:

  • Downstream packages drop support for Python 3.9 entirely.
  • Downstream packages require Numpy 1.x for Python 3.9 (numpy <2; python_version < "3.10")
  • Pint makes a new release that's compatible with both Python 3.9 and Numpy 2.0. I think this ought to be easy in principle - it's only been a few months since Pint dropped 3.9 support - but I spent a while on it, and unfortunately neither undoing the 3.9 changes nor redoing the numpy changes was straightforward.

@andrewgsavage
Copy link
Collaborator

  • Pint makes a new release that's compatible with both Python 3.9 and Numpy 2.0. I think this ought to be easy in principle - it's only been a few months since Pint dropped 3.9 support - but I spent a while on it, and unfortunately neither undoing the 3.9 changes nor redoing the numpy changes was straightforward.

I'm not opposed to this. Was this https://github.com/takluyver/pint/tree/0.23-np-2.0 what you tried? Did you look at making 0.24 work with 3.9?

@andrewgsavage andrewgsavage reopened this Jun 21, 2024
@andrewgsavage andrewgsavage changed the title release before numpy=2.0? pint 0.24 / numpy 2.0 / python 3.9 issues Jun 21, 2024
@takluyver
Copy link
Contributor

takluyver commented Jun 21, 2024 via email

@andrewgsavage andrewgsavage pinned this issue Jun 21, 2024
@andrewgsavage
Copy link
Collaborator

I've got 0.24 working with py39 #2019 so I'll make 0.24.1 available for py39.
some seemingly unrelated failures though...

@takluyver
Copy link
Contributor

takluyver commented Jun 21, 2024 via email

@andrewgsavage
Copy link
Collaborator

I think the all PRs needed to fix issues for 0.24.1 are now merged. would be good to confirm the babel issue #2006

@andrewgsavage
Copy link
Collaborator

0.24.1 released

@takluyver
Copy link
Contributor

Thanks @andrewgsavage !

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 a pull request may close this issue.

7 participants