Skip to content

Commit

Permalink
Merge pull request #689 from PCMDI/687_remove_deprecated_numpy_aliases
Browse files Browse the repository at this point in the history
Remove deprecated NumPy aliases for int and float
  • Loading branch information
mauzey1 authored Jan 10, 2023
2 parents 5f8759e + 37f4117 commit 304db22
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ aliases:
export UVCDAT_ANONYMOUS_LOG=False
# run tests again but with cdms2 installed
set +e
conda create -y -n cdms2_py$PYTHON_VERSION --use-local $CHANNELS python=$PYTHON_VERSION $PKG_NAME=$VERSION $PKGS $CONDA_COMPILERS cdms2
conda create -y -n cdms2_py$PYTHON_VERSION --use-local $CHANNELS python=$PYTHON_VERSION $PKG_NAME=$VERSION $PKGS $CONDA_COMPILERS cdms2 numpy=1.23
conda activate cdms2_py$PYTHON_VERSION
./configure --prefix=$CONDA_PREFIX --with-python --with-uuid=$CONDA_PREFIX --with-json-c=$CONDA_PREFIX --with-udunits2=$CONDA_PREFIX --with-netcdf=$CONDA_PREFIX --enable-verbose-test
set -e
Expand Down
35 changes: 15 additions & 20 deletions Lib/pywrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,14 @@ def time_varying_grid_coordinate(
raise Exception(
'error unknown data_type: "%s", must be one of: "c","d","f","l","i"')

if not isinstance(grid_id, (int, numpy.int, numpy.int32, numpy.int64)):
if not isinstance(grid_id, (int, numpy.int32, numpy.int64)):
raise Exception("error grid_id must be an integer")

grid_id = int(grid_id)

if missing_value is not None:
if not isinstance(missing_value, (float, int,
numpy.float, numpy.float32, numpy.float64,
numpy.int, numpy.int32, numpy.int64)):
if not isinstance(missing_value, (float, int, numpy.float32, numpy.float64,
numpy.int32, numpy.int64)):
raise Exception(
"error missing_value must be a number, you passed: %s" %
type(missing_value))
Expand Down Expand Up @@ -535,17 +534,15 @@ def variable(table_entry, units, axis_ids, data_type='f', missing_value=None,
else:
comment = str(comment)

if not isinstance(tolerance, (float, int,
numpy.float, numpy.float32, numpy.float64,
numpy.int, numpy.int32, numpy.int64)):
if not isinstance(tolerance, (float, int, numpy.float32, numpy.float64,
numpy.int32, numpy.int64)):
raise Exception("error tolerance must be a number")

tolerance = float(tolerance)

if missing_value is not None:
if not isinstance(missing_value, (float, int,
numpy.float, numpy.float32, numpy.float64,
numpy.int, numpy.int32, numpy.int64)):
if not isinstance(missing_value, (float, int, numpy.float32, numpy.float64,
numpy.int32, numpy.int64)):
raise Exception(
"error missing_value must be a number, you passed: %s" %
repr(missing_value))
Expand All @@ -560,7 +557,7 @@ def variable(table_entry, units, axis_ids, data_type='f', missing_value=None,
def zfactor(zaxis_id, zfactor_name, units="", axis_ids=None,
data_type=None, zfactor_values=None, zfactor_bounds=None):

if not isinstance(zaxis_id, (int, numpy.int, numpy.int32, numpy.int64)):
if not isinstance(zaxis_id, (int, numpy.int32, numpy.int64)):
raise Exception("error zaxis_id must be a number")
zaxis_id = int(zaxis_id)

Expand All @@ -583,7 +580,7 @@ def zfactor(zaxis_id, zfactor_name, units="", axis_ids=None,
axis_ids = numpy.ascontiguousarray(axis_ids)
elif axis_ids is None:
pass
elif isinstance(axis_ids, (int, numpy.int, numpy.int32, numpy.int64)):
elif isinstance(axis_ids, (int, numpy.int32, numpy.int64)):
axis_ids = numpy.array([axis_ids, ])
elif not isinstance(axis_ids, numpy.ndarray):
raise Exception(
Expand All @@ -598,8 +595,7 @@ def zfactor(zaxis_id, zfactor_name, units="", axis_ids=None,
ndims = len(axis_ids)

if zfactor_values is not None:
if isinstance(zfactor_values, (float, int, numpy.float,
numpy.float32, numpy.int, numpy.int32)):
if isinstance(zfactor_values, (float, int, numpy.float32, numpy.int32)):
zfactor_values = numpy.array((zfactor_values,))
elif numpy.ma.isMA(zfactor_values):
zfactor_values = numpy.ascontiguousarray(zfactor_values.filled())
Expand All @@ -617,10 +613,9 @@ def zfactor(zaxis_id, zfactor_name, units="", axis_ids=None,
try:
data_type = zfactor_values.dtype.char
except BaseException:
if isinstance(zfactor_values,
(float, numpy.float, numpy.float32)):
if isinstance(zfactor_values, (float, numpy.float32)):
data_type = 'f'
elif isinstance(zfactor_values, (int, numpy.int, numpy.int32)):
elif isinstance(zfactor_values, (int, numpy.int32)):
data_type = 'd'
else:
raise Exception(
Expand Down Expand Up @@ -681,15 +676,15 @@ def write(var_id, data, ntimes_passed=None, file_suffix="",
Usage:
ierr = write(var_id,data,ntimes_passed=None,file_suffix="",time_vals=None,time_bnds=None,store_with=None
"""
if not isinstance(var_id, (int, numpy.int, numpy.int32, numpy.int64)):
if not isinstance(var_id, (int, numpy.int32, numpy.int64)):
raise Exception("error var_id must be an integer")
var_id = int(var_id)

if not isinstance(file_suffix, six.string_types):
raise Exception("Error file_suffix must be a string")

if store_with is not None:
if not isinstance(store_with, (int, numpy.int, numpy.int32, numpy.int64)):
if not isinstance(store_with, (int, numpy.int32, numpy.int64)):
raise Exception("error store_with must be an integer")
store_with = int(store_with)

Expand Down Expand Up @@ -739,7 +734,7 @@ def write(var_id, data, ntimes_passed=None, file_suffix="",
ntimes_passed = 0
else:
ntimes_passed = len(time_vals)
if not isinstance(ntimes_passed, (int, numpy.int, numpy.int32, numpy.int64)):
if not isinstance(ntimes_passed, (int, numpy.int32, numpy.int64)):
raise Exception("error ntimes_passed must be an integer")
ntimes_passed = int(ntimes_passed)

Expand Down
2 changes: 1 addition & 1 deletion Test/test_python_2Gb_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
coord_vals=lons,
cell_bounds=blons,
units='degrees_east')
# ,coord_vals=numpy.arange(ntimes,dtype=numpy.float),cell_bounds=numpy.arange(ntimes+1,dtype=float),units='months since 2000')
# ,coord_vals=numpy.arange(ntimes,dtype=float),cell_bounds=numpy.arange(ntimes+1,dtype=float),units='months since 2000')
itim = cmor.axis(table_entry='time', units='months since 2010')
ilev = cmor.axis(table_entry='plev19',
coord_vals=numpy.array([1000.,
Expand Down
2 changes: 1 addition & 1 deletion Test/test_python_2Gb_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
coord_vals=lons,
cell_bounds=blons,
units='degrees_east')
# ,coord_vals=numpy.arange(ntimes,dtype=numpy.float),cell_bounds=numpy.arange(ntimes+1,dtype=float),units='months since 2000')
# ,coord_vals=numpy.arange(ntimes,dtype=float),cell_bounds=numpy.arange(ntimes+1,dtype=float),units='months since 2000')
itim = cmor.axis(table_entry='time', units='months since 2010')
ilev = cmor.axis(table_entry='plev19', coord_vals=levs, units='hPa')

Expand Down
2 changes: 1 addition & 1 deletion Test/test_python_open_close_cmor_multiple.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
units='degrees_east')
itim = cmor.axis(
table_entry='time', coord_vals=numpy.arange(
ntimes, dtype=numpy.float), cell_bounds=numpy.arange(
ntimes, dtype=float), cell_bounds=numpy.arange(
ntimes + 1, dtype=float), units='months since 2000')
ilev = cmor.axis(table_entry='plev19',
coord_vals=numpy.array([1000.,
Expand Down

0 comments on commit 304db22

Please sign in to comment.