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

Adapt satpy to numpy 2 #2579

Merged
merged 8 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion satpy/readers/aapp_mhs_amsub_l1c.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _calibrate(data,
if calib_type == 'counts':
return channel

channel = channel.astype(np.float_)
channel = channel.astype(np.float64)

return da.where(mask, channel, np.nan)

Expand Down
2 changes: 1 addition & 1 deletion satpy/readers/hdf4_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, filename, filename_info, filetype_info):
def _collect_attrs(self, name, attrs):
for key, value in attrs.items():
value = np.squeeze(value)
if issubclass(value.dtype.type, (np.string_, np.unicode_)) and not value.shape:
if issubclass(value.dtype.type, (np.bytes_, np.str_)) and not value.shape:
value = value.item() # convert to scalar
if not isinstance(value, str):
# python 3 - was scalar numpy array of bytes
Expand Down
2 changes: 1 addition & 1 deletion satpy/readers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def np2str(value):

"""
if hasattr(value, 'dtype') and \
issubclass(value.dtype.type, (np.str_, np.string_, np.object_)) \
issubclass(value.dtype.type, (np.str_, np.bytes_, np.object_)) \
and value.size == 1:
value = value.item()
if not isinstance(value, str):
Expand Down
12 changes: 6 additions & 6 deletions satpy/tests/reader_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,20 @@ def test_sub_area(self, adef):
def test_np2str(self):
"""Test the np2str function."""
# byte object
npstring = np.string_('hej')
self.assertEqual(hf.np2str(npstring), 'hej')
npbytes = np.bytes_('hej')
self.assertEqual(hf.np2str(npbytes), 'hej')

# single element numpy array
np_arr = np.array([npstring])
np_arr = np.array([npbytes])
self.assertEqual(hf.np2str(np_arr), 'hej')

# scalar numpy array
np_arr = np.array(npstring)
np_arr = np.array(npbytes)
self.assertEqual(hf.np2str(np_arr), 'hej')

# multi-element array
npstring = np.array([npstring, npstring])
self.assertRaises(ValueError, hf.np2str, npstring)
npbytes = np.array([npbytes, npbytes])
self.assertRaises(ValueError, hf.np2str, npbytes)

# non-array
self.assertRaises(ValueError, hf.np2str, 5)
Expand Down
2 changes: 1 addition & 1 deletion satpy/tests/writer_tests/test_cf.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def get_test_attrs(self):
'numpy_bool': True,
'numpy_void': np.void(0),
'numpy_bytes': np.bytes_('test'),
'numpy_string': np.string_('test'),
'numpy_string': np.str_('test'),
'list': [1, 2, np.float64(3)],
'nested_list': ["1", ["2", [3]]],
'bool': True,
Expand Down
8 changes: 4 additions & 4 deletions satpy/writers/cf_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,15 @@
if netCDF4 is None and h5netcdf is None:
raise ImportError('Ensure that the netCDF4 or h5netcdf package is installed.')

# Numpy datatypes compatible with all netCDF4 backends. ``np.unicode_`` is
# Numpy datatypes compatible with all netCDF4 backends. ``np.str_`` is
# excluded because h5py (and thus h5netcdf) has problems with unicode, see
# https://github.com/h5py/h5py/issues/624."""
NC4_DTYPES = [np.dtype('int8'), np.dtype('uint8'),
np.dtype('int16'), np.dtype('uint16'),
np.dtype('int32'), np.dtype('uint32'),
np.dtype('int64'), np.dtype('uint64'),
np.dtype('float32'), np.dtype('float64'),
np.string_]
np.bytes_]

# Unsigned and int64 isn't CF 1.7 compatible
# Note: Unsigned and int64 are CF 1.9 compatible
Expand All @@ -209,7 +209,7 @@
np.dtype('int32'),
np.dtype('float32'),
np.dtype('float64'),
np.string_]
np.bytes_]

CF_VERSION = 'CF-1.7'

Expand Down Expand Up @@ -582,7 +582,7 @@ def _remove_satpy_attrs(new_data):
def _format_prerequisites_attrs(dataarray):
"""Reformat prerequisites attribute value to string."""
if 'prerequisites' in dataarray.attrs:
dataarray.attrs['prerequisites'] = [np.string_(str(prereq)) for prereq in dataarray.attrs['prerequisites']]
dataarray.attrs['prerequisites'] = [np.bytes_(str(prereq)) for prereq in dataarray.attrs['prerequisites']]
return dataarray


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from setuptools import find_packages, setup

requires = ['numpy >=1.13', 'pillow', 'pyresample >=1.24.0', 'trollsift',
requires = ['numpy >=1.21', 'pillow', 'pyresample >=1.24.0', 'trollsift',
'trollimage >=1.20', 'pykdtree', 'pyyaml >=5.1', 'xarray >=0.10.1, !=0.13.0',
'dask[array] >=0.17.1', 'pyproj>=2.2', 'zarr', 'donfig', 'appdirs',
'packaging', 'pooch', 'pyorbital']
Expand Down
Loading