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

Add support for float numpy>=1.24 #597

Merged
merged 1 commit into from
Oct 28, 2023
Merged

Conversation

jaku-jaku
Copy link
Contributor

@jaku-jaku jaku-jaku commented Feb 7, 2023

  • numpy float deprecated

@ethzasl-jenkins
Copy link

Can one of the admins verify this patch?

@jaku-jaku jaku-jaku changed the title Minor Fixes Minor Fixes for run-time Feb 7, 2023
@goldbattle
Copy link
Collaborator

Does this have backwards compatibility? What version of OS / libs are you using?

@jaku-jaku
Copy link
Contributor Author

jaku-jaku commented Feb 10, 2023

Does this have backwards compatibility? What version of OS / libs are you using?

OS: Ubuntu 20.04 | ROS Noetic | Python 3.8.10 | numpy: 1.24.1

import numpy as np
np.float

Output:

AttributeError: module 'numpy' has no attribute 'float'

As stated in numpy 1.20 - deprecations, it will be no longer supported due to duplication.
Hence, I believe it is not backward compatible from numpy 1.20

@Dead-Hand Dead-Hand mentioned this pull request Jul 17, 2023
@adthoms
Copy link

adthoms commented Sep 26, 2023

@goldbattle are there plans to merge this PR?

@goldbattle
Copy link
Collaborator

I have not had time to reproduce in a docker container and ensure it has backwards compatibility. Need to also verify that this is the only place that needs it, and likely create a ubuntu 22 docker.

@jaku-jaku
Copy link
Contributor Author

I have not had time to reproduce in a docker container and ensure it has backwards compatibility. Need to also verify that this is the only place that needs it, and likely create a ubuntu 22 docker.

Try to check your numpy version in your docker.
I think is to do with numpy version, either add requirements.txt to enforce numpy<1.20.0, or apply this changes with 'numpy>=1.20.0'.

@jaku-jaku
Copy link
Contributor Author

jaku-jaku commented Oct 21, 2023

As refer from https://stackoverflow.com/questions/74844262/how-can-i-solve-error-module-numpy-has-no-attribute-float-in-python

NumPy 1.20 (release notes) deprecated numpy.float, numpy.int, and similar aliases, causing them to issue a deprecation warning
NumPy 1.24 (release notes) removed these aliases altogether, causing an error when they are used

I will make a test locally and update this PR with backward support

  • verify program breaks after numpy==1.24.0
pip3 install numpy==1.24

now run calibration:

  File "{my-path}/kalibr/aslam_offline_calibration/kalibr/python/kalibr_camera_calibration/CameraUtils.py", line 123, in getReprojectionErrorStatistics
    mean = np.mean(rerr_matrix, 0, dtype=np.float)
  File "{my-home}/.local/lib/python3.8/site-packages/numpy/__init__.py", line 284, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'float'
  • backward support

+ but np.float64 has been supported still
@jaku-jaku
Copy link
Contributor Author

Fixes tested:

Python 3.8.10 (default, May 26 2023, 14:05:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.float
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jx/.local/lib/python3.8/site-packages/numpy/__init__.py", line 284, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'float'
>>> numpy.float64
<class 'numpy.float64'>
>>> numpy.version.version
'1.24.0'

and backward $ pip3 install numpy==1.17.4

Python 3.8.10 (default, May 26 2023, 14:05:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.float
<class 'float'>
>>> numpy.float64
<class 'numpy.float64'>
>>> numpy.version.version
'1.17.4'

@jaku-jaku
Copy link
Contributor Author

@adthoms @goldbattle Done, and tested for backward and forward compatible.

You can replicate the above issue on the main branch by pip install numpy==1.24, and you will see the error.
You can remove the issue by setting pip install numpy==1.23 or specify np.float64 (with this latest fix)

@jaku-jaku jaku-jaku changed the title Minor Fixes for run-time Add support for float numpy>=1.24 Oct 21, 2023
@goldbattle goldbattle merged commit 6b2359f into ethz-asl:master Oct 28, 2023
3 checks passed
@goldbattle
Copy link
Collaborator

Many thanks for the detailed PR and steps to test, was able to reproduce and this PR fixed the issues. Many thanks.

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.

4 participants