ethz-asl / kalibr

The Kalibr visual-inertial calibration toolbox
Other
4.28k stars 1.39k forks source link

Add support for float numpy>=1.24 #597

Closed jaku-jaku closed 10 months ago

jaku-jaku commented 1 year ago
ethzasl-jenkins commented 1 year ago

Can one of the admins verify this patch?

goldbattle commented 1 year ago

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

jaku-jaku commented 1 year ago

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

adthoms commented 11 months ago

@goldbattle are there plans to merge this PR?

goldbattle commented 11 months ago

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 commented 11 months ago

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 commented 10 months ago

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

jaku-jaku commented 10 months ago

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 commented 10 months ago

@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)

goldbattle commented 10 months ago

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