Skip to content

Commit 343d329

Browse files
Stop using deprecated aliases of builtin types (#3997)
* Stopped using deprecated aliases of builtin types. This is required to avoid warnings starting with NumPy 1.20.0. * Update lib/iris/tests/test_cell.py Co-authored-by: Bill Little <[email protected]> * Update lib/iris/tests/test_cell.py Co-authored-by: Bill Little <[email protected]> * Updated whatsnew. Co-authored-by: Bill Little <[email protected]>
1 parent ce5975a commit 343d329

27 files changed

+105
-94
lines changed

docs/src/whatsnew/latest.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,15 @@ This document explains the changes made to Iris for this release
112112
#. `@bjlittle`_ enabled `cirrus-ci`_ compute credits for non-draft pull-requests
113113
from collaborators targeting the Iris ``master`` branch. (:pull:`4007`)
114114

115+
#. `@akuhnregnier`_ replaced `deprecated numpy 1.20 aliases for builtin types`_.
116+
(:pull:`3997`)
117+
115118

116119
.. comment
117120
Whatsnew author names (@github name) in alphabetical order. Note that,
118121
core dev names are automatically included by the common_links.inc:
119122
123+
.. _@akuhnregnier: https://github.com/akuhnregnier
120124
.. _@gcaria: https://github.com/gcaria
121125
.. _@MHBalsmeier: https://github.com/MHBalsmeier
122126

@@ -125,6 +129,7 @@ This document explains the changes made to Iris for this release
125129
Whatsnew resources in alphabetical order:
126130
127131
.. _abstract base class: https://docs.python.org/3/library/abc.html
132+
.. _deprecated numpy 1.20 aliases for builtin types: https://numpy.org/doc/1.20/release/1.20.0-notes.html#using-the-aliases-of-builtin-types-like-np-int-is-deprecated
128133
.. _GitHub: https://github.com/SciTools/iris/issues/new/choose
129134
.. _Met Office: https://www.metoffice.gov.uk/
130135
.. _numpy: https://numpy.org/doc/stable/release/1.20.0-notes.html

lib/iris/_constraints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def call_func(c):
294294
except TypeError:
295295
try_quick = False
296296
if try_quick:
297-
r = np.zeros(coord.shape, dtype=np.bool)
297+
r = np.zeros(coord.shape, dtype=np.bool_)
298298
if coord.cell(i) == self._coord_thing:
299299
r[i] = True
300300
else:

lib/iris/analysis/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ def interp_order(length):
14541454
slices[-1] = endslice
14551455
slices = tuple(slices) # Numpy>=1.16 : index with tuple, *not* list.
14561456

1457-
if isinstance(array.dtype, np.float):
1457+
if isinstance(array.dtype, np.float64):
14581458
data = array[slices]
14591459
else:
14601460
# Cast non-float data type.

lib/iris/analysis/_regrid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ def _regrid(
696696

697697
if ma.isMaskedArray(src_data):
698698
data = ma.empty(shape, dtype=dtype)
699-
data.mask = np.zeros(data.shape, dtype=np.bool)
699+
data.mask = np.zeros(data.shape, dtype=np.bool_)
700700
else:
701701
data = np.empty(shape, dtype=dtype)
702702

lib/iris/experimental/regrid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,9 @@ def _regrid_area_weighted_array(src_data, x_dim, y_dim, weights_info, mdtol=0):
498498
# Flag to indicate whether the original data was a masked array.
499499
src_masked = src_data.mask.any() if ma.isMaskedArray(src_data) else False
500500
if src_masked:
501-
src_area_masks = np.full(src_areas_shape, True, dtype=np.bool)
501+
src_area_masks = np.full(src_areas_shape, True, dtype=np.bool_)
502502
else:
503-
new_data_mask = np.full(new_shape, False, dtype=np.bool)
503+
new_data_mask = np.full(new_shape, False, dtype=np.bool_)
504504

505505
# Axes of data over which the weighted mean is calculated.
506506
axis = (y_dim, x_dim)

lib/iris/fileformats/_ff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ def __iter__(self):
816816
return pp._interpret_fields(self._extract_field())
817817

818818

819-
def _parse_binary_stream(file_like, dtype=np.float, count=-1):
819+
def _parse_binary_stream(file_like, dtype=np.float64, count=-1):
820820
"""
821821
Replacement :func:`numpy.fromfile` due to python3 performance issues.
822822

lib/iris/fileformats/pp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ def _data_bytes_to_shaped_array(
752752
# However, we still mask any MDI values in the array (below).
753753
pass
754754
else:
755-
land_mask = mask.data.astype(np.bool)
755+
land_mask = mask.data.astype(np.bool_)
756756
sea_mask = ~land_mask
757757
new_data = np.ma.masked_all(land_mask.shape)
758758
new_data.fill_value = mdi

lib/iris/fileformats/pp_load_rules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ def _epoch_date_hours(epoch_hours_unit, datetime):
580580
# numpy.float64. The behaviour of round is to recast this to an
581581
# int, which is not the desired behaviour for PP files.
582582
# So, cast the answer to numpy.float_ to be safe.
583-
epoch_hours = np.float_(epoch_hours_unit.date2num(datetime))
583+
epoch_hours = np.float64(epoch_hours_unit.date2num(datetime))
584584

585585
if days_offset is not None:
586586
# Correct for any modifications to achieve a valid date.

lib/iris/tests/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,26 +483,26 @@ def assertDataAlmostEqual(self, data, reference_filename, **kwargs):
483483
stats.get("max", 0.0),
484484
stats.get("min", 0.0),
485485
),
486-
dtype=np.float_,
486+
dtype=np.float64,
487487
)
488488
if math.isnan(stats.get("mean", 0.0)):
489489
self.assertTrue(math.isnan(data.mean()))
490490
else:
491491
data_stats = np.array(
492492
(data.mean(), data.std(), data.max(), data.min()),
493-
dtype=np.float_,
493+
dtype=np.float64,
494494
)
495495
self.assertArrayAllClose(nstats, data_stats, **kwargs)
496496
else:
497497
self._ensure_folder(reference_path)
498498
stats = collections.OrderedDict(
499499
[
500-
("std", np.float_(data.std())),
501-
("min", np.float_(data.min())),
502-
("max", np.float_(data.max())),
500+
("std", np.float64(data.std())),
501+
("min", np.float64(data.min())),
502+
("max", np.float64(data.max())),
503503
("shape", data.shape),
504504
("masked", ma.is_masked(data)),
505-
("mean", np.float_(data.mean())),
505+
("mean", np.float64(data.mean())),
506506
]
507507
)
508508
with open(reference_path, "w") as reference_file:

lib/iris/tests/experimental/regrid/test_regrid_conservative_via_esmpy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ def test_rotated(self):
675675
[100, 100, 100, 100, 100, 100, 100, 100, 100],
676676
[100, 100, 100, 100, 100, 100, 100, 100, 100],
677677
],
678-
dtype=np.float,
678+
dtype=np.float64,
679679
)
680680

681681
c1_areasum = _cube_area_sum(c1)
@@ -715,7 +715,7 @@ def test_rotated(self):
715715
[100, 100, 199, 199, 100],
716716
[100, 100, 199, 199, 199],
717717
],
718-
dtype=np.float,
718+
dtype=np.float64,
719719
)
720720
c2_areasum = _cube_area_sum(c2)
721721

@@ -770,7 +770,7 @@ def test_missing_data_rotated(self):
770770
[100, 100, 100, 100, 100, 100, 100, 100, 100],
771771
[100, 100, 100, 100, 100, 100, 100, 100, 100],
772772
],
773-
dtype=np.float,
773+
dtype=np.float64,
774774
)
775775

776776
if do_add_missing:

0 commit comments

Comments
 (0)