CDAT / cdms

8 stars 10 forks source link

cdms2 conflict with latest numpy version #449

Open lee1043 opened 7 months ago

lee1043 commented 7 months ago

numpy.float (e.g., used here is deprecated since numpy 1.20, need to replace it to numpy.float64.

f = cdms2.open(path) with latest numpy version returns below error.

 File "/Users/lee1043/mambaforge/envs/pmp_devel_20230223/lib/python3.9/site-packages/cdms2/dataset.py", line 523, in openDataset
    file = CdmsFile(path, mode, hostObj)
  File "/Users/lee1043/mambaforge/envs/pmp_devel_20230223/lib/python3.9/site-packages/cdms2/dataset.py", line 1348, in __init__
    self.variables[name] = FileVariable(
  File "/Users/lee1043/mambaforge/envs/pmp_devel_20230223/lib/python3.9/site-packages/cdms2/fvariable.py", line 21, in __init__
    DatasetVariable.__init__(self, parent, varname)
  File "/Users/lee1043/mambaforge/envs/pmp_devel_20230223/lib/python3.9/site-packages/cdms2/variable.py", line 74, in __init__
    self._numericType_ = numpy.float
  File "/Users/lee1043/mambaforge/envs/pmp_devel_20230223/lib/python3.9/site-packages/numpy/__init__.py", line 305, in __getattr__
    raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

I understand cdms2 is no longer under active development, so leaving this error for documenting it.

jypeter commented 7 months ago

Good idea to this documentation issue!

Do you know precisely which version of numpy is the last one compatible with cdms2 (i.e. where np.float is deprecated, but still available)? You may then update the issue title to include this information, like cdms2 is incompatible with numpy > vvvvv

I have just checked my current (though slightly obsolete) environment, and np.float is still available in numpy 1.21.4

(cdatm_py3)  >conda list | egrep '(cdms|numpy)'
cdms2                     3.1.5                    pypi_0    pypi
libcdms                   3.1.2              h981a4fd_113    conda-forge
numpy                     1.21.4           py38he2449b9_0    conda-forge
numpy_groupies            0.9.22             pyhd8ed1ab_0    conda-forge
numpydoc                  1.1.0                      py_1    conda-forge

(cdatm_py3)  >python
Python 3.8.8 | packaged by conda-forge | (default, Feb 20 2021, 16:22:27)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> fl_test = np.float(3)
<stdin>:1: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
>>> fl_test
3.0
>>> type(fl_test)
<class 'float'>
>>>
jypeter commented 7 months ago

I have just found this old issue, that seemed to deal with handling new data types

Update cdms2 to deal with all common datatypes (uint8, uint16, char, str etc)

If, by chance, an existing issue documents an easy way to update all the required types, and a knowledgeable person (that's not me) can implement a quick fix of cdms2, it would not hurt ! <3

lee1043 commented 7 months ago

Good idea, I think the last numpy version that works with cdms2 is 1.23.5.

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