AttributeError: module 'numpy' has no attribute 'float'.
quickbrett opened this issue · comments
This small example retrurns an error
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
fig = plt.figure(figsize=(8, 6), edgecolor="w")
m = Basemap(projection="moll", resolution=None, lat_0=0, lon_0=0)
m.drawmapboundary()
m.shadedrelief(scale=0.2)
The error message:
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 belive, the wrong attribute is used in packages/basemap/src/mpl_toolkits/basemap/__init__.py
, master branch, line 4186.
This small patch works for me:
4186c4186
< x1 = np.array(ny*[0.5*(self.xmax + self.xmin)],np.float)
---
> x1 = np.array(ny*[0.5*(self.xmax + self.xmin)],np.float32)
Thanks for the great package!
Thanks for pointing the bug! Just out of curiosity, which numpy
version are you using?
I'm using the following versions:
- matplotlib 3.7.3
- numpy 1.25.2
- basemap 1.3.8
@quickbrett thanks for raising this issue and proposing the fix and @molinav thanks for maintaining this still great package. I actually got the same error, I think it is related to the latest numpy versions.
It seems that numpy.float
was removed with its release 1.24.0 (https://numpy.org/devdocs/release/1.24.0-notes.html). I will replace it with the Python builtin float
as suggested in the link.
Hopefully I can get some time soon to start a basic unit test collection, because these issues would be identified immediately with the automatic tests.
@quickbrett I just added the patch in a hotfix branch (1.3.9), your small example now works after the correction. I took this moment to correct all the references to numpy.float
that I found in the whole library, mostly replaced with numpy.float64
.
I am not sure when I will release 1.3.9, maybe I will do a couple of bugfixes more that are still around before tagging.
@molinav I installes the hotfix branch
pip install git+https://github.com/matplotlib/basemap@hotfix-1.3.9#subdirectory=packages/basemap
Hence I'm using the following package versions (pip list
):
- basemap 1.3.9
- numpy 1.25.2
- matplotlib 3.7.3
I tested the new version with a few simple examples and it worked for me.
Thanks!
@quickbrett I have just added a couple of unit tests for Basemap.shadedrelief
based on your snippet, so I am finally closing this issue. The bugfix will come with basemap
1.3.9 (hopefully soon).