diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ba432fc..8f9d9c2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,6 +37,12 @@ jobs: pip install -r .github/workflows/requirements-${{ matrix.req-version }}.txt pip install pytest pytest-cov coveralls pip install . + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 lazyarray --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 lazyarray.py --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Run tests run: | pytest --cov=lazyarray -v diff --git a/README.rst b/README.rst index 84130f2..0010fb7 100644 --- a/README.rst +++ b/README.rst @@ -23,10 +23,8 @@ and memory in cases where: .. image:: https://readthedocs.org/projects/lazyarray/badge/?version=latest :target: http://lazyarray.readthedocs.io/en/latest/ -.. image:: https://travis-ci.org/NeuralEnsemble/lazyarray.svg?branch=master - :target: https://travis-ci.org/NeuralEnsemble/lazyarray/ +.. image:: https://github.com/NeuralEnsemble/lazyarrays/actions/workflows/test.yml/badge.svg + :target: https://github.com/NeuralEnsemble/lazyarray/actions .. image:: https://coveralls.io/repos/github/NeuralEnsemble/lazyarray/badge.svg?branch=master :target: https://coveralls.io/github/NeuralEnsemble/lazyarray?branch=master - - diff --git a/lazyarray.py b/lazyarray.py index 42a33fa..ec873c9 100644 --- a/lazyarray.py +++ b/lazyarray.py @@ -154,7 +154,6 @@ def is_array_like(value): return True - class larray(object): """ Optimises storage of and operations on arrays in various ways: @@ -170,7 +169,6 @@ class larray(object): on different nodes or in different threads. """ - def __init__(self, value, shape=None, dtype=None): """ Create a new lazy array. @@ -202,7 +200,7 @@ def __init__(self, value, shape=None, dtype=None): elif not isinstance(value, np.ndarray): value = np.array(value, dtype=dtype) elif dtype is not None: - assert np.can_cast(value.dtype, dtype, casting='safe') # or could convert value to the provided dtype + assert np.can_cast(value.dtype, dtype, casting='safe') # or could convert value to the provided dtype if shape and value.shape and value.shape != shape: raise ValueError("Array has shape %s, value has shape %s" % (shape, value.shape)) if value.shape: @@ -244,8 +242,10 @@ def __deepcopy__(self, memo): else: try: obj.base_value = deepcopy(self.base_value) - except TypeError: # base_value cannot be copied, e.g. is a generator (but see generator_tools from PyPI) - obj.base_value = self.base_value # so here we create a reference rather than deepcopying - could cause problems + except TypeError: + # base_value cannot be copied, e.g. is a generator (but see generator_tools from PyPI) + # so here we create a reference rather than deepcopying - could cause problems + obj.base_value = self.base_value obj._shape = self._shape obj.dtype = self.dtype obj.operations = [] @@ -257,15 +257,13 @@ def __deepcopy__(self, memo): return obj def __repr__(self): - return "" % (self.base_value, - self.shape, - self.dtype, - self.operations) + return "" % ( + self.base_value, self.shape, self.dtype, self.operations) def _set_shape(self, value): if (hasattr(self.base_value, "shape") and self.base_value.shape and # values of type np.float have an empty shape - self.base_value.shape != value): + self.base_value.shape != value): raise ValueError("Lazy array has fixed shape %s, cannot be changed to %s" % (self.base_value.shape, value)) self._shape = value for op in self.operations: @@ -298,9 +296,11 @@ def size(self): @property def is_homogeneous(self): """True if all the elements of the array are the same.""" - hom_base = isinstance(self.base_value, (int, np.integer, float, bool)) \ - or type(self.base_value) == self.dtype \ - or (isinstance(self.dtype, type) and isinstance(self.base_value, self.dtype)) + hom_base = ( + isinstance(self.base_value, (int, np.integer, float, bool)) + or type(self.base_value) == self.dtype + or (isinstance(self.dtype, type) and isinstance(self.base_value, self.dtype)) + ) hom_ops = all(obj.is_homogeneous for f, obj in self.operations if isinstance(obj, larray)) return hom_base and hom_ops @@ -326,9 +326,9 @@ def axis_indices(x, max): return x elif isinstance(x, slice): # need to handle negative values in slice return np.arange((x.start or 0), - (x.stop or max), - (x.step or 1), - dtype=int) + (x.stop or max), + (x.step or 1), + dtype=int) elif isinstance(x, Sized): if hasattr(x, 'dtype') and x.dtype == bool: return np.arange(max)[x] @@ -509,7 +509,7 @@ def evaluate(self, simplify=False, empty_val=0): if x.shape != self._shape: x = x.reshape(self._shape) elif have_scipy and sparse.issparse(self.base_value): # For sparse matrices - if empty_val!=0: + if empty_val != 0: x = self.base_value.toarray((sparse.csc_matrix)) x = np.where(x, x, np.nan) else: