1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
Description: fix build time test failure with python3.10
This is a naive implementation targeting debian for fetching items in the
module collections.abc instead of plain collections, which is deprecated sinc
python3.10.
.
There is an independently developed patch upstream much more generic which
should make it in the next version hopefully.
Author: Étienne Mollier <emollier@debian.org>
Bug: https://github.com/NeuralEnsemble/lazyarray/pull/14
Last-Update: 2021-12-11
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- lazyarray.orig/lazyarray.py
+++ lazyarray/lazyarray.py
@@ -72,7 +72,7 @@
elif isinstance(x, slice):
y = min(max, x.stop or max) # slice limits can go past the bounds
return 1 + (y - (x.start or 0) - 1) // (x.step or 1)
- elif isinstance(x, collections.Sized):
+ elif isinstance(x, collections.abc.Sized):
if hasattr(x, 'dtype') and x.dtype == bool:
return x.sum()
else:
@@ -83,7 +83,7 @@
addr = full_address(addr, full_shape)
if isinstance(addr, np.ndarray) and addr.dtype == bool:
return (addr.sum(),)
- elif all(isinstance(x, collections.Sized) for x in addr):
+ elif all(isinstance(x, collections.abc.Sized) for x in addr):
return (len(addr[0]),)
else:
shape = [size(x, max) for (x, max) in zip(addr, full_shape)]
@@ -130,11 +130,11 @@
def is_array_like(value):
# False for numbers, generators, functions, iterators
- if not isinstance(value, collections.Sized):
+ if not isinstance(value, collections.abc.Sized):
return False
if sparse.issparse(value):
return True
- if isinstance(value, collections.Mapping):
+ if isinstance(value, collections.abc.Mapping):
# because we may wish to have lazy arrays in which each
# item is a dict, for example
return False
@@ -322,7 +322,7 @@
(x.stop or max),
(x.step or 1),
dtype=int)
- elif isinstance(x, collections.Sized):
+ elif isinstance(x, collections.abc.Sized):
if hasattr(x, 'dtype') and x.dtype == bool:
return np.arange(max)[x]
else:
@@ -335,7 +335,7 @@
return (np.arange(self._shape[0])[addr],)
else:
raise NotImplementedError()
- elif all(isinstance(x, collections.Sized) for x in addr):
+ elif all(isinstance(x, collections.abc.Sized) for x in addr):
indices = [np.array(x) for x in addr]
return indices
else:
@@ -343,8 +343,8 @@
if len(indices) == 1:
return indices
elif len(indices) == 2:
- if isinstance(indices[0], collections.Sized):
- if isinstance(indices[1], collections.Sized):
+ if isinstance(indices[0], collections.abc.Sized):
+ if isinstance(indices[1], collections.abc.Sized):
mesh_xy = np.meshgrid(*indices)
return (mesh_xy[0].T, mesh_xy[1].T) # meshgrid works on (x,y), not (i,j)
return indices
@@ -394,7 +394,7 @@
base_val = base_val[0]
elif partial_shape and base_val.shape != partial_shape:
base_val = base_val.reshape(partial_shape)
- elif isinstance(self.base_value, collections.Iterator):
+ elif isinstance(self.base_value, collections.abc.Iterator):
raise NotImplementedError("coming soon...")
else:
raise ValueError("invalid base value for array (%s)" % self.base_value)
@@ -414,7 +414,7 @@
elif isinstance(x, slice):
lower = x.start or 0
upper = min(x.stop or size - 1, size - 1) # slices are allowed to go past the bounds
- elif isinstance(x, collections.Sized):
+ elif isinstance(x, collections.abc.Sized):
if is_boolean_array(x):
lower = 0
upper = x.size - 1
@@ -504,7 +504,7 @@
x = np.where(x, x, np.nan)
else:
x = self.base_value.toarray((sparse.csc_matrix))
- elif isinstance(self.base_value, collections.Iterator):
+ elif isinstance(self.base_value, collections.abc.Iterator):
x = np.fromiter(self.base_value, dtype=self.dtype or float, count=self.size)
if x.shape != self._shape:
x = x.reshape(self._shape)
|