From dd885bef15814f588b58944d2505296df4aaae0e Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Mon, 8 Feb 2021 12:32:49 -0600 Subject: [PATCH] Fix Numpy 1.20 warnings. --- awkward0/array/base.py | 6 +++--- awkward0/array/chunked.py | 4 ++-- awkward0/array/indexed.py | 4 ++-- awkward0/array/jagged.py | 24 ++++++++++++------------ awkward0/array/masked.py | 18 +++++++++--------- awkward0/array/table.py | 6 +++--- awkward0/array/union.py | 4 ++-- awkward0/array/virtual.py | 4 ++-- awkward0/generate.py | 2 +- awkward0/persist.py | 4 ++-- awkward0/version.py | 2 +- 11 files changed, 39 insertions(+), 39 deletions(-) diff --git a/awkward0/array/base.py b/awkward0/array/base.py index 477e5d03..70316c77 100644 --- a/awkward0/array/base.py +++ b/awkward0/array/base.py @@ -375,11 +375,11 @@ def VirtualArray(self): @classmethod def _util_isinteger(cls, x): - return isinstance(x, (numbers.Integral, cls.numpy.integer)) and not isinstance(x, (bool, cls.numpy.bool_, cls.numpy.bool)) + return isinstance(x, (numbers.Integral, cls.numpy.integer)) and not isinstance(x, (bool, cls.numpy.bool_)) @classmethod def _util_isintegertype(cls, x): - return issubclass(x, cls.numpy.integer) and not issubclass(x, (cls.numpy.bool_, cls.numpy.bool)) + return issubclass(x, cls.numpy.integer) and not issubclass(x, (bool, cls.numpy.bool_)) @classmethod def _util_toarray(cls, value, defaultdtype, passthrough=None): @@ -621,7 +621,7 @@ def _util_isstringslice(cls, where): return False elif isinstance(where, (cls.numpy.ndarray, AwkwardArray)) and issubclass(where.dtype.type, (numpy.str, numpy.str_)): return True - elif isinstance(where, (cls.numpy.ndarray, AwkwardArray)) and issubclass(where.dtype.type, (numpy.object, numpy.object_)) and not issubclass(where.dtype.type, (numpy.bool, numpy.bool_)): + elif isinstance(where, (cls.numpy.ndarray, AwkwardArray)) and issubclass(where.dtype.type, (numpy.object, numpy.object_)) and not issubclass(where.dtype.type, (bool, numpy.bool_)): return len(where) > 0 and all(isinstance(x, awkward0.util.string) for x in where) elif isinstance(where, (cls.numpy.ndarray, AwkwardArray)): return False diff --git a/awkward0/array/chunked.py b/awkward0/array/chunked.py index 38a55728..225f01ae 100644 --- a/awkward0/array/chunked.py +++ b/awkward0/array/chunked.py @@ -479,7 +479,7 @@ def __getitem__(self, where): else: raise NotImplementedError - elif len(head.shape) == 1 and issubclass(head.dtype.type, (self.numpy.bool, self.numpy.bool_)): + elif len(head.shape) == 1 and issubclass(head.dtype.type, (bool, self.numpy.bool_)): if len(self) != len(head): raise IndexError("boolean index did not match indexed array along dimension 0; dimension is {0} but corresponding boolean dimension is {1}".format(len(self), len(head))) @@ -735,7 +735,7 @@ def _prepare(self, ufunc, identity, dtype): if self._chunksizes[chunkid] > 0: this = chunk[:self._chunksizes[chunkid]] if out is None: - if dtype is None and issubclass(this.dtype.type, (self.numpy.bool_, self.numpy.bool)): + if dtype is None and issubclass(this.dtype.type, (bool, self.numpy.bool_)): dtype = self.numpy.dtype(type(identity)) if dtype is None: dtype = this.dtype diff --git a/awkward0/array/indexed.py b/awkward0/array/indexed.py index 6c7b3ba0..662ec7de 100644 --- a/awkward0/array/indexed.py +++ b/awkward0/array/indexed.py @@ -570,7 +570,7 @@ def __getitem__(self, where): return self.copy(length=length, index=index, content=content)[tail] - elif isinstance(head, SparseArray) and len(head.shape) == 1 and issubclass(head.dtype.type, (self.numpy.bool, self.numpy.bool_)): + elif isinstance(head, SparseArray) and len(head.shape) == 1 and issubclass(head.dtype.type, (bool, self.numpy.bool_)): head._valid() if self._length != head._length: raise IndexError("boolean index did not match indexed array along dimension 0; dimension is {0} but corresponding boolean dimension is {1}".format(self._length, head._length)) @@ -595,7 +595,7 @@ def __getitem__(self, where): else: head = self._util_toarray(head, self.INDEXTYPE) - if len(head.shape) == 1 and issubclass(head.dtype.type, (self.numpy.bool, self.numpy.bool_)): + if len(head.shape) == 1 and issubclass(head.dtype.type, (bool, self.numpy.bool_)): if self._length != len(head): raise IndexError("boolean index did not match indexed array along dimension 0; dimension is {0} but corresponding boolean dimension is {1}".format(self._length, len(head))) diff --git a/awkward0/array/jagged.py b/awkward0/array/jagged.py index ff7bf522..bb25cebc 100644 --- a/awkward0/array/jagged.py +++ b/awkward0/array/jagged.py @@ -559,7 +559,7 @@ def __getitem__(self, where): return self.copy(starts=head._starts, stops=head._stops, content=self._content[indexes]) - elif len(head.shape) == 1 and issubclass(head._content.dtype.type, (self.numpy.bool, self.numpy.bool_)): + elif len(head.shape) == 1 and issubclass(head._content.dtype.type, (bool, self.numpy.bool_)): try: offsets = self.offsets thyself = self @@ -588,7 +588,7 @@ def __getitem__(self, where): return self.copy(starts=offsets[:-1].reshape(intheadsum.shape), stops=offsets[1:].reshape(intheadsum.shape), content=thyself._content[headcontent]) - elif head.shape == self.shape and issubclass(head._content.dtype.type, (self.numpy.bool, self.numpy.bool_)): + elif head.shape == self.shape and issubclass(head._content.dtype.type, (bool, self.numpy.bool_)): index = self.localindex + self.starts flatindex = index.flatten()[head.flatten()] return type(self).fromcounts(head.sum(), self._content[flatindex]) @@ -747,7 +747,7 @@ def __getitem__(self, where): index += node._starts node = node._content[index] - elif len(head.shape) == 1 and issubclass(head.dtype.type, (self.numpy.bool, self.numpy.bool_)): + elif len(head.shape) == 1 and issubclass(head.dtype.type, (bool, self.numpy.bool_)): if wasslice: stack = [] for x in range(nslices): @@ -826,7 +826,7 @@ def __setitem__(self, where, what): self._content[indexes] = what - elif issubclass(where._content.dtype.type, (self.numpy.bool, self.numpy.bool_)): + elif issubclass(where._content.dtype.type, (bool, self.numpy.bool_)): index = self.localindex + self.starts flatindex = index.flatten()[where.flatten()] self._content[flatindex] = what @@ -982,7 +982,7 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): except TypeError: pass else: - if "first" not in locals() or isinstance(first, (numbers.Number, self.numpy.bool_, self.numpy.bool, self.numpy.number)): + if "first" not in locals() or isinstance(first, (numbers.Number, bool, self.numpy.bool_, self.numpy.number)): inputs[i] = self.numpy.array(inputs[i], copy=False) else: inputs[i] = self.JaggedArray.fromiter(inputs[i]) @@ -1527,7 +1527,7 @@ def _reduce(self, ufunc, identity, dtype): content = content.copy() content[mask] = identity - if dtype is None and issubclass(content.dtype.type, (self.numpy.bool_, self.numpy.bool)): + if dtype is None and issubclass(content.dtype.type, (bool, self.numpy.bool_)): dtype = self.numpy.dtype(type(identity)) if dtype is None: dtype = content.dtype @@ -1535,13 +1535,13 @@ def _reduce(self, ufunc, identity, dtype): content = content.astype(dtype) if identity == self.numpy.inf: - if issubclass(dtype.type, (self.numpy.bool_, self.numpy.bool)): + if issubclass(dtype.type, (bool, self.numpy.bool_)): identity = True elif self._util_isintegertype(dtype.type): identity = self.numpy.iinfo(dtype.type).max elif identity == -self.numpy.inf: - if issubclass(dtype.type, (self.numpy.bool_, self.numpy.bool)): + if issubclass(dtype.type, (bool, self.numpy.bool_)): identity = False elif self._util_isintegertype(dtype.type): identity = self.numpy.iinfo(dtype.type).min @@ -1802,13 +1802,13 @@ def ready(x): columns1[n] = x._content elif isinstance(x, Iterable): columns1[n] = first.tojagged(x)._content - elif isinstance(x, (numbers.Number, numpy.number, numpy.bool, numpy.bool_)): + elif isinstance(x, (numbers.Number, numpy.number, bool, numpy.bool_)): columns1[n] = JaggedArray(first._starts, first._stops, numpy.full(first._stops.max(), columns1, dtype=type(columns1)))._content else: raise TypeError("unrecognized type for JaggedArray.zip: {0}".format(type(x))) elif isinstance(columns1, Iterable): columns1 = first.tojagged(columns1)._content - elif isinstance(columns1, (numbers.Number, numpy.number, numpy.bool, numpy.bool_)): + elif isinstance(columns1, (numbers.Number, numpy.number, bool, numpy.bool_)): columns1 = JaggedArray(first._starts, first._stops, numpy.full(first._stops.max(), columns1, dtype=type(columns1)))._content else: raise TypeError("unrecognized type for JaggedArray.zip: {0}".format(type(columns1))) @@ -1819,7 +1819,7 @@ def ready(x): columns2[i] = x._content elif not isinstance(x, dict) and isinstance(x, Iterable): columns2[i] = first.tojagged(x)._content - elif isinstance(x, (numbers.Number, numpy.number, numpy.bool, numpy.bool_)): + elif isinstance(x, (numbers.Number, numpy.number, bool, numpy.bool_)): columns2[i] = JaggedArray(first._starts, first._stops, numpy.full(first._stops.max(), x, dtype=type(x)))._content else: raise TypeError("unrecognized type for JaggedArray.zip: {0}".format(type(x))) @@ -1830,7 +1830,7 @@ def ready(x): columns3[n] = x._content elif not isinstance(x, dict) and isinstance(x, Iterable): columns3[n] = first.tojagged(x)._content - elif isinstance(x, (numbers.Number, numpy.number, numpy.bool, numpy.bool_)): + elif isinstance(x, (numbers.Number, numpy.number, bool, numpy.bool_)): columns3[n] = JaggedArray(first._starts, first._stops, numpy.full(first._stops.max(), x, dtype=type(x)))._content else: raise TypeError("unrecognized type for JaggedArray.zip: {0}".format(type(x))) diff --git a/awkward0/array/masked.py b/awkward0/array/masked.py index 38cfaf0d..038f7d81 100644 --- a/awkward0/array/masked.py +++ b/awkward0/array/masked.py @@ -94,7 +94,7 @@ def mask(self, value): if self.check_prop_valid: if len(value.shape) != 1: raise ValueError("mask must have 1-dimensional shape") - if not issubclass(value.dtype.type, (self.numpy.bool_, self.numpy.bool)): + if not issubclass(value.dtype.type, (bool, self.numpy.bool_)): value = (value != 0) self._mask = value self._isvalid = False @@ -344,7 +344,7 @@ def _prepare(self, ufunc, identity, dtype): return out if isinstance(self._content, self.numpy.ndarray): - if dtype is None and issubclass(self._content.dtype.type, (self.numpy.bool_, self.numpy.bool)): + if dtype is None and issubclass(self._content.dtype.type, (bool, self.numpy.bool_)): dtype = self.numpy.dtype(type(identity)) if ufunc is None: content = self.numpy.zeros(self._content.shape, dtype=self.numpy.float32) @@ -370,12 +370,12 @@ def _prepare(self, ufunc, identity, dtype): dtype = content.dtype if identity == self.numpy.inf: - if issubclass(dtype.type, (self.numpy.bool_, self.numpy.bool)): + if issubclass(dtype.type, (bool, self.numpy.bool_)): identity = True elif self._util_isintegertype(dtype.type): identity = self.numpy.iinfo(dtype.type).max elif identity == -self.numpy.inf: - if issubclass(dtype.type, (self.numpy.bool_, self.numpy.bool)): + if issubclass(dtype.type, (bool, self.numpy.bool_)): identity = False elif self._util_isintegertype(dtype.type): identity = self.numpy.iinfo(dtype.type).min @@ -503,7 +503,7 @@ def bool2bit(cls, boolmask, lsborder=False): boolmask = cls._util_toarray(boolmask, cls.MaskedArray.fget(None).MASKTYPE, cls.numpy.ndarray) if len(boolmask.shape) != 1: raise ValueError("boolmask must have 1-dimensional shape") - if not issubclass(boolmask.dtype.type, (cls.numpy.bool_, cls.numpy.bool)): + if not issubclass(boolmask.dtype.type, (bool, cls.numpy.bool_)): boolmask = (boolmask != 0) if lsborder: @@ -627,7 +627,7 @@ def _maskwhere(self, where): self.numpy.bitwise_and(bitmasks, self._mask[byteposes], bitmasks) return bitmasks.astype(self.numpy.bool_) - elif len(where.shape) == 1 and issubclass(where.dtype.type, (self.numpy.bool, self.numpy.bool_)): + elif len(where.shape) == 1 and issubclass(where.dtype.type, (bool, self.numpy.bool_)): # scales with the size of the mask anyway, so go ahead and unpack the whole mask unpacked = self.numpy.unpackbits(self._mask).view(self.MASKTYPE) @@ -868,7 +868,7 @@ def _prepare(self, ufunc, identity, dtype): return out if isinstance(self._content, self.numpy.ndarray): - if dtype is None and issubclass(self._content.dtype.type, (self.numpy.bool_, self.numpy.bool)): + if dtype is None and issubclass(self._content.dtype.type, (bool, self.numpy.bool_)): dtype = self.numpy.dtype(type(identity)) if dtype is None: content = self._content @@ -878,13 +878,13 @@ def _prepare(self, ufunc, identity, dtype): content = self._content._prepare(ufunc, identity, dtype) if identity == self.numpy.inf: - if issubclass(dtype.type, (self.numpy.bool_, self.numpy.bool)): + if issubclass(dtype.type, (bool, self.numpy.bool_)): identity = True elif self._util_isintegertype(dtype.type): identity = self.numpy.iinfo(dtype.type).max elif identity == -self.numpy.inf: - if issubclass(dtype.type, (self.numpy.bool_, self.numpy.bool)): + if issubclass(dtype.type, (bool, self.numpy.bool_)): identity = False elif self._util_isintegertype(dtype.type): identity = self.numpy.iinfo(dtype.type).min diff --git a/awkward0/array/table.py b/awkward0/array/table.py index 075c03c9..1ecb9a5c 100644 --- a/awkward0/array/table.py +++ b/awkward0/array/table.py @@ -541,7 +541,7 @@ def _newslice(self, head): else: return self._view[head] - elif issubclass(head.dtype.type, (self.numpy.bool, self.numpy.bool_)): + elif issubclass(head.dtype.type, (bool, self.numpy.bool_)): length = self._length() if len(head) != length: raise IndexError("boolean index of length {0} does not fit array of length {1}".format(len(head), length)) @@ -713,7 +713,7 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): out = None for x in newcolumns.values(): assert isinstance(x, self.numpy.ndarray) - assert issubclass(x.dtype.type, (self.numpy.bool_, self.numpy.bool)) + assert issubclass(x.dtype.type, (bool, self.numpy.bool_)) if out is None: out = x else: @@ -856,7 +856,7 @@ def _prepare(self, ufunc, identity, dtype): out = self.copy(contents={}) for n, x in self._contents.items(): if isinstance(x, self.numpy.ndarray): - if dtype is None and issubclass(x.dtype.type, (self.numpy.bool_, self.numpy.bool)): + if dtype is None and issubclass(x.dtype.type, (bool, self.numpy.bool_)): dtype = self.numpy.dtype(type(identity)) if dtype is not None: x = x.astype(dtype) diff --git a/awkward0/array/union.py b/awkward0/array/union.py index 9a47d67f..522a25ac 100644 --- a/awkward0/array/union.py +++ b/awkward0/array/union.py @@ -163,7 +163,7 @@ def contents(self, value): @classmethod def uniondtype(cls, arrays): - if all(issubclass(x.dtype.type, (cls.numpy.bool_, cls.numpy.bool)) for x in arrays): + if all(issubclass(x.dtype.type, (bool, cls.numpy.bool_)) for x in arrays): return cls.numpy.dtype(cls.numpy.bool_) elif all(issubclass(x.dtype.type, (cls.numpy.int8)) for x in arrays): @@ -501,7 +501,7 @@ def _reduce(self, ufunc, identity, dtype): return ufunc.reduce(prepared) def _prepare(self, ufunc, identity, dtype): - if dtype is None and issubclass(self.dtype.type, (self.numpy.bool_, self.numpy.bool)): + if dtype is None and issubclass(self.dtype.type, (bool, self.numpy.bool_)): dtype = self.numpy.dtype(type(identity)) if dtype is None: dtype = self.dtype diff --git a/awkward0/array/virtual.py b/awkward0/array/virtual.py index ae2da966..851fc5d8 100644 --- a/awkward0/array/virtual.py +++ b/awkward0/array/virtual.py @@ -205,7 +205,7 @@ def persistvirtual(self): @persistvirtual.setter def persistvirtual(self, value): if self.check_prop_valid: - if not isinstance(value, (bool, self.numpy.bool_, self.numpy.bool)): + if not isinstance(value, (bool, self.numpy.bool_)): raise TypeError("persistvirtual must be boolean") self._persistvirtual = bool(value) @@ -454,7 +454,7 @@ def _reduce(self, ufunc, identity, dtype): def _prepare(self, ufunc, identity, dtype): array = self.array if isinstance(array, self.numpy.ndarray): - if dtype is None and issubclass(array.dtype.type, (self.numpy.bool_, self.numpy.bool)): + if dtype is None and issubclass(array.dtype.type, (bool, self.numpy.bool_)): dtype = self.numpy.dtype(type(identity)) if dtype is None: return array diff --git a/awkward0/generate.py b/awkward0/generate.py index 890e979d..8cd875cc 100644 --- a/awkward0/generate.py +++ b/awkward0/generate.py @@ -19,7 +19,7 @@ def typeof(obj): if obj is None: return None - elif isinstance(obj, (bool, numpy.bool_, numpy.bool)): + elif isinstance(obj, (bool, numpy.bool_)): return BoolFillable elif isinstance(obj, (numbers.Number, awkward0.numpy.number)): return NumberFillable diff --git a/awkward0/persist.py b/awkward0/persist.py index e96ccca3..5ce4eb2e 100644 --- a/awkward0/persist.py +++ b/awkward0/persist.py @@ -24,7 +24,7 @@ import awkward0.version compression = [ - {"minsize": 8192, "types": [numpy.bool_, numpy.bool, numpy.integer], "contexts": "*", "pair": (zlib.compress, ("zlib", "decompress"))}, + {"minsize": 8192, "types": [bool, numpy.bool_, numpy.integer], "contexts": "*", "pair": (zlib.compress, ("zlib", "decompress"))}, ] whitelist = [ @@ -231,7 +231,7 @@ def jsonable(obj): elif isinstance(obj, str): return str(obj) - elif isinstance(obj, (bool, numpy.bool_, numpy.bool)): + elif isinstance(obj, (bool, numpy.bool_)): return bool(obj) # policy: eliminate Numpy types elif isinstance(obj, (numbers.Integral, numpy.integer)): diff --git a/awkward0/version.py b/awkward0/version.py index 67078aeb..7d43250c 100644 --- a/awkward0/version.py +++ b/awkward0/version.py @@ -4,7 +4,7 @@ import re -__version__ = "0.15.4" +__version__ = "0.15.5" version = __version__ version_info = tuple(re.split(r"[-\.]", __version__))