ramonhagenaars / nptyping

💡 Type hints for Numpy and Pandas
MIT License
576 stars 29 forks source link

numpy deprecation warnings when importing nptyping #102

Open dstansby opened 1 year ago

dstansby commented 1 year ago

I'm doing some testing of a package that has nptyping in the dependency chain, and when I catch the warnigns as erros with pytest some warnings are coming from nptyping:

   .tox/py38/lib/python3.8/site-packages/nrrd/formatters.py:3: in <module>
      import nptyping as npt
  .tox/py38/lib/python3.8/site-packages/nptyping/__init__.py:32: in <module>
      from nptyping.ndarray import NDArray
  .tox/py38/lib/python3.8/site-packages/nptyping/ndarray.py:40: in <module>
      from nptyping.shape import Shape
  .tox/py38/lib/python3.8/site-packages/nptyping/shape.py:29: in <module>
      from nptyping.shape_expression import (
  .tox/py38/lib/python3.8/site-packages/nptyping/shape_expression.py:36: in <module>
      from nptyping.typing_ import ShapeExpression, ShapeTuple
  .tox/py38/lib/python3.8/site-packages/nptyping/typing_.py:54: in <module>
      Object0 = np.object0
  .tox/py38/lib/python3.8/site-packages/numpy/__init__.py:294: in __getattr__
      warnings.warn(msg, DeprecationWarning, stacklevel=2)
  E   DeprecationWarning: `np.object0` is a deprecated alias for ``np.object0` is a deprecated alias for `np.object_`. `object` can be used instead.  (Deprecated NumPy 1.24)`.  (Deprecated NumPy 1.24)
rfechtner commented 1 year ago

Any update on this topic? Should be rather fix to implement, dropping the legacy types. I don't mind drawing an MR for this - I an just a a bit too short sighted to fully grasp some further reaching implications.

anosillus commented 1 year ago

It appears that the some type API in NumPy has changed since NumPy 1.24, starting from May 23. Some nptyping API no longer work with the latest version of NumPy. I'm conducting research to send a fix pull request. I expect it will be easy to follow the new one, but harder to ensure backward compatibility. Is it a good idea to use conditional branching to handle this?

anosillus commented 1 year ago

The reason nptyping no longer works with the latest version of NumPy is likely due to these changes.

https://github.com/numpy/numpy/pull/22607 https://github.com/numpy/numpy/pull/22385

anosillus commented 1 year ago

Currently, calling nptyping in the latest numpy environment result in an error. I can send a pull request immediately if I just erase the API that is diprecated in numpy from nptyping to solve that, but is that the right policy? If there are no problems, I will make that pull request in this weekend.