Skip to content

Replace np.float with float for NumPy dtype specification

Problem

NumPy 1.20 deprecated the use of np.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

Solution

Replace lines like:

zu = numpy.zeros(output.variables['zu'].shape, numpy.float)

with:

zu = numpy.zeros(output.variables['zu'].shape, float)

For this special case, there is an even better solution, using numpy.zeros_like:

zu = numpy.zeros_like(output.variables['zu'])

Full error message:

(pitlakq39) C:\Users\Spencer>pitlakq run pitlakq_tut
.......................

runtime: 0:00:03.989770
Traceback (most recent call last):
  File "C:\Users\Spencer\anaconda3\envs\pitlakq39\Scripts\pitlakq-script.py", line 33, in <module>
    sys.exit(load_entry_point('PITLAKQ==1.6.1', 'console_scripts', 'pitlakq')())
  File "C:\Users\Spencer\anaconda3\envs\pitlakq39\lib\site-packages\pitlakq\metamodel\running\run_pitlakq.py", line 517, in main
    args.func(args)
  File "C:\Users\Spencer\anaconda3\envs\pitlakq39\lib\site-packages\pitlakq\metamodel\running\run_pitlakq.py", line 450, in run_project
    run(args.project_name)
  File "C:\Users\Spencer\anaconda3\envs\pitlakq39\lib\site-packages\pitlakq\metamodel\running\run_pitlakq.py", line 549, in run
    model.run(config.gw_time_step, config.lake_time_step, first,
  File "C:\Users\Spencer\anaconda3\envs\pitlakq39\lib\site-packages\pitlakq\metamodel\running\run_pitlakq.py", line 336, in run
    self.lake.run(until,
  File "C:\Users\Spencer\anaconda3\envs\pitlakq39\lib\site-packages\pitlakq\submodels\lake\lake.py", line 453, in run
    self.output.write_independent_output()
  File "C:\Users\Spencer\anaconda3\envs\pitlakq39\lib\site-packages\pitlakq\commontools\output\ncoutput.py", line 173, in write_independent_output
    zu = numpy.zeros(output.variables['zu'].shape, numpy.float)
  File "C:\Users\Spencer\anaconda3\envs\pitlakq39\lib\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
Edited by hydrocomputing