Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
Fix Numpy 1.20 warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski committed Feb 8, 2021
1 parent 0b109f3 commit dd885be
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 39 deletions.
6 changes: 3 additions & 3 deletions awkward0/array/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions awkward0/array/chunked.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions awkward0/array/indexed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)))

Expand Down
24 changes: 12 additions & 12 deletions awkward0/array/jagged.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -1527,21 +1527,21 @@ 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
else:
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
Expand Down Expand Up @@ -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)))
Expand All @@ -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)))
Expand All @@ -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)))
Expand Down
18 changes: 9 additions & 9 deletions awkward0/array/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions awkward0/array/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions awkward0/array/union.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions awkward0/array/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion awkward0/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions awkward0/persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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)):
Expand Down
2 changes: 1 addition & 1 deletion awkward0/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import re

__version__ = "0.15.4"
__version__ = "0.15.5"
version = __version__
version_info = tuple(re.split(r"[-\.]", __version__))

Expand Down

0 comments on commit dd885be

Please sign in to comment.