Skip to content

Commit

Permalink
deal with deprecated numpy.bool, float
Browse files Browse the repository at this point in the history
  • Loading branch information
jswhit committed Jan 13, 2021
1 parent bcbe3a0 commit d50b949
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
==================================
* move CI/CD tests from travis/appveyor to Github Actions (PR #1061).
* move netCDF4 dir under src so module can be imported in source directory (PR #1062).
* change numpy.bool to numpy.bool_ and numpy.float to numpy.float_ (float and
bool are deprecated in numpy 1.20, issue #1065)

version 1.5.5.1 (tag v1.5.5.1rel)
==================================
Expand Down
10 changes: 5 additions & 5 deletions src/netCDF4/_netCDF4.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ for storing numpy complex arrays. Here's an example:
>>> # create sample complex data.
>>> datac = numpy.exp(1j*(1.+numpy.linspace(0, numpy.pi, size)))
>>> # create complex128 compound data type.
>>> complex128 = numpy.dtype([("real",numpy.float64),("imag",numpy.float64)])
>>> complex128 = numpy.dtype([("real",numpy.float_64),("imag",numpy.float_64)])

This comment has been minimized.

Copy link
@eric-wieser

eric-wieser Feb 1, 2021

This change is incorrect

>>> complex128_t = f.createCompoundType(complex128,"complex128")
>>> # create a variable with this data type, write some data to it.
>>> x_dim = f.createDimension("x_dim",None)
Expand Down Expand Up @@ -4556,15 +4556,15 @@ rename a `netCDF4.Variable` attribute named `oldname` to `newname`."""
data = data.view(dtype_unsigned_int)
# private function for creating a masked array, masking missing_values
# and/or _FillValues.
totalmask = numpy.zeros(data.shape, numpy.bool)
totalmask = numpy.zeros(data.shape, numpy.bool_)
fill_value = None
safe_missval = self._check_safecast('missing_value')
if safe_missval:
mval = numpy.array(self.missing_value, self.dtype)
if self.scale and is_unsigned_int:
mval = mval.view(dtype_unsigned_int)
# create mask from missing values.
mvalmask = numpy.zeros(data.shape, numpy.bool)
mvalmask = numpy.zeros(data.shape, numpy.bool_)
if mval.shape == (): # mval a scalar.
mval = [mval] # make into iterable.
for m in mval:
Expand Down Expand Up @@ -4927,13 +4927,13 @@ cannot be safely cast to variable data type""" % attname
# if auto scaling is to be done, don't cast to an integer yet.
if self.scale and self.dtype.kind in 'iu' and \
hasattr(self, 'scale_factor') or hasattr(self, 'add_offset'):
data = numpy.array(data,numpy.float)
data = numpy.array(data,numpy.float_)
else:
data = numpy.array(data,self.dtype)

# for Enum variable, make sure data is valid.
if self._isenum:
test = numpy.zeros(data.shape,numpy.bool)
test = numpy.zeros(data.shape,numpy.bool_)
if ma.isMA(data):
# fix for new behaviour in numpy.ma in 1.13 (issue #662)
for val in self.datatype.enum_dict.values():
Expand Down

0 comments on commit d50b949

Please sign in to comment.