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

numpy.alen() called by numpy_func, but alen() is deprecated #1532

Closed
sharonzitara opened this issue Jun 3, 2022 · 4 comments · Fixed by #1678
Closed

numpy.alen() called by numpy_func, but alen() is deprecated #1532

sharonzitara opened this issue Jun 3, 2022 · 4 comments · Fixed by #1678

Comments

@sharonzitara
Copy link

In the latest pre-release of NumPy (https://github.com/numpy/numpy/releases/tag/v1.23.0rc2), alen has been removed due to its deprecation expiring. Pint's numpy_func is still calling alen here.

NumPy 1.18.0 release notes indicate that len should be used instead.

@sharonzitara sharonzitara changed the title numpy.alen() called by numpy_func numpy.alen() called by numpy_func, but alen() is deprecated Jun 23, 2022
@sharonzitara sharonzitara changed the title numpy.alen() called by numpy_func, but alen() is deprecated numpy.alen() called by numpy_func, but alen() is deprecated Jun 23, 2022
@wenx-z
Copy link

wenx-z commented Jun 23, 2022

Would definitely appreciate an update here! This is breaking our production pipelines.

@jules-ch
Copy link
Collaborator

@wenx-z can you describe the error you encounter ?
it should work even if the numpy version have removed it.

@wenx-z
Copy link

wenx-z commented Jun 23, 2022

from pint import UnitRegistry
  File ".../env/lib/python3.8/site-packages/pint/__init__.py", line 28, in <module>
    from .measurement import Measurement
  File ".../env/lib/python3.8/site-packages/pint/measurement.py", line 12, in <module>
    from .quantity import Quantity
  File ".../env/lib/python3.8/site-packages/pint/quantity.py", line 47, in <module>
    from .numpy_func import (
  File ".../env/lib/python3.8/site-packages/pint/numpy_func.py", line 860, in <module>
    implement_func("function", func_str, input_units=None, output_unit=None)
  File ".../env/lib/python3.8/site-packages/pint/numpy_func.py", line 263, in implement_func
    func = getattr(np, func_str_split[0])
  File ".../env/lib/python3.8/site-packages/numpy/__init__.py", line 311, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'alen'

@keewis
Copy link
Contributor

keewis commented Jun 23, 2022

well, that makes sense to me: __array_function__ registers by function object, not by name, so we need to access the attribute. This is a easy fix, though: remove a single line plus a test (if that exists).

Feel free to send in a PR, @wenx-z (no pressure, though).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants