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

issue in pygrid with np.int and np.warnings #252

Open
andreldeod opened this issue Apr 21, 2024 · 0 comments
Open

issue in pygrid with np.int and np.warnings #252

andreldeod opened this issue Apr 21, 2024 · 0 comments

Comments

@andreldeod
Copy link

andreldeod commented Apr 21, 2024

Hey I ran into an issue using the pygrid module in this notebook.

It uses np.int and np.warnings, which are deprecated or don't exist.

  • np.int should be replaced with np.int_

  • np.warnings should be replaced with warnings

I tried modifying pygrid with the modifications mentioned and the code worked for me.

Here's some of my error messages:

np.int:
`File /srv/conda/envs/hydrosar/lib/python3.11/site-packages/pysheds/pgrid.py:1854, in Grid.compute_hand(self, fdir, dem, drainage_mask, out_name, dirmap, nodata_in_fdir, nodata_in_dem, nodata_out, routing, inplace, apply_mask, ignore_metadata, return_index, **kwargs)
1852 r_dirmap = np.array(dirmap)[[4, 5, 6, 7, 0, 1, 2, 3]].tolist()
1853 source = np.flatnonzero(mask)
-> 1854 hand = -np.ones(fdir.size, dtype=np.int)
1855 hand[source] = source
1856 for _ in range(fdir.size):

File /srv/conda/envs/hydrosar/lib/python3.11/site-packages/numpy/init.py:324, in getattr(attr)
319 warnings.warn(
320 f"In the future np.{attr} will be defined as the "
321 "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
323 if attr in former_attrs:
--> 324 raise AttributeError(former_attrs[attr])
326 if attr == 'testing':
327 import numpy.testing as testing

AttributeError: module 'numpy' has no attribute 'int'.
np.int was a deprecated alias for the builtin int. To avoid this error in existing code, use int by itself. Doing this will not modify any behavior and is safe. When replacing np.int, you may wish to use e.g. np.int64 or np.int32 to specify the precision. If you wish to review your current use, check the release note link for additional information.
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`

np.warnings:
`File ~/GuyanaFlooding/pgrid_modified.py:720, in Grid._d8_flowdir(self, dem, dem_mask, out_name, nodata_in, nodata_out, pits, flats, dirmap, inplace, as_crs, apply_mask, ignore_metadata, properties, metadata, **kwargs)
716 def _d8_flowdir(self, dem=None, dem_mask=None, out_name='dir', nodata_in=None, nodata_out=0,
717 pits=-1, flats=-1, dirmap=(64, 128, 1, 2, 4, 8, 16, 32), inplace=True,
718 as_crs=None, apply_mask=False, ignore_metadata=False, properties={},
719 metadata={}, **kwargs):
--> 720 np.warnings.filterwarnings(action='ignore', message='Invalid value encountered',
721 category=RuntimeWarning)
722 try:
723 # Make sure nothing flows to the nodata cells
724 dem.flat[dem_mask] = dem.max() + 1

File /srv/conda/envs/hydrosar/lib/python3.11/site-packages/numpy/init.py:333, in getattr(attr)
330 "Removed in NumPy 1.25.0"
331 raise RuntimeError("Tester was removed in NumPy 1.25.")
--> 333 raise AttributeError("module {!r} has no attribute "
334 "{!r}".format(name, attr))

AttributeError: module 'numpy' has no attribute 'warnings'`

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

No branches or pull requests

1 participant