Skip to content

Commit 3c93752

Browse files
update pre-commit config (#8)
Update pre-commit configuration to use ruff as the default linter. Increased line width of ruff to 120. Kind of works in most scenarios. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ebdd763 commit 3c93752

19 files changed

+244
-171
lines changed

.coveragerc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# .coveragerc to control coverage.py
22
[run]
33
branch = True
4-
source = delayedarray
4+
source = delayedarray
55
# omit = bad_file.py
66

77
[paths]

.github/workflows/pypi-publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ jobs:
4848
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
4949
with:
5050
user: __token__
51-
password: ${{ secrets.PYPI_PASSWORD }}
51+
password: ${{ secrets.PYPI_PASSWORD }}

.github/workflows/pypi-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ jobs:
3232
# # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
3333
- name: Test with tox
3434
run: |
35-
tox
35+
tox

.pre-commit-config.yaml

+13-28
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,34 @@ repos:
1717
- id: mixed-line-ending
1818
args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows
1919

20-
## If you want to automatically "modernize" your Python code:
21-
# - repo: https://github.com/asottile/pyupgrade
22-
# rev: v3.7.0
23-
# hooks:
24-
# - id: pyupgrade
25-
# args: ['--py37-plus']
26-
27-
## If you want to avoid flake8 errors due to unused vars or imports:
28-
# - repo: https://github.com/PyCQA/autoflake
29-
# rev: v2.1.1
30-
# hooks:
31-
# - id: autoflake
32-
# args: [
33-
# --in-place,
34-
# --remove-all-unused-imports,
35-
# --remove-unused-variables,
36-
# ]
37-
38-
- repo: https://github.com/PyCQA/isort
39-
rev: 5.12.0
20+
- repo: https://github.com/PyCQA/docformatter
21+
rev: v1.7.5
4022
hooks:
41-
- id: isort
23+
- id: docformatter
24+
additional_dependencies: [tomli]
25+
args: [-r, --black, -in-place]
26+
# --config, ./pyproject.toml
4227

4328
- repo: https://github.com/psf/black
4429
rev: 23.7.0
4530
hooks:
4631
- id: black
4732
language_version: python3
4833

34+
- repo: https://github.com/astral-sh/ruff-pre-commit
35+
# Ruff version.
36+
rev: v0.0.285
37+
hooks:
38+
- id: ruff
39+
args: [--fix, --exit-non-zero-on-fix]
40+
4941
## If like to embrace black styles even in the docs:
5042
# - repo: https://github.com/asottile/blacken-docs
5143
# rev: v1.13.0
5244
# hooks:
5345
# - id: blacken-docs
5446
# additional_dependencies: [black]
5547

56-
- repo: https://github.com/PyCQA/flake8
57-
rev: 6.1.0
58-
hooks:
59-
- id: flake8
60-
## You can add flake8 plugins via `additional_dependencies`:
61-
# additional_dependencies: [flake8-bugbear]
62-
6348
## Check for misspells in documentation files:
6449
# - repo: https://github.com/codespell-project/codespell
6550
# rev: v2.2.5

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
## Version 0.0.3
88

9-
- separate dense and sparse matrix classes
9+
- separate dense and sparse matrix classes

docs/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
furo
12
# Requirements file for ReadTheDocs, check .readthedocs.yml.
23
# To build the module reference correctly, make sure every external package
34
# under `install_requires` in `setup.cfg` is also listed here!
45
# sphinx_rtd_theme
56
myst-parser[linkify]
67
sphinx>=3.2.1
7-
furo

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ build-backend = "setuptools.build_meta"
99
version_scheme = "no-guess-dev"
1010

1111
[tool.ruff]
12-
line-length = 100
12+
line-length = 120
1313
src = ["src"]
14+
exclude = ["tests"]
1415

1516
[tool.ruff.pydocstyle]
1617
convention = "google"

setup.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
"""
2-
Setup file for DelayedArray.
3-
Use setup.cfg to configure your project.
1+
"""Setup file for DelayedArray. Use setup.cfg to configure your project.
42
5-
This file was generated with PyScaffold 4.5.
6-
PyScaffold helps you to put up the scaffold of your new Python project.
7-
Learn more under: https://pyscaffold.org/
3+
This file was generated with PyScaffold 4.5.
4+
PyScaffold helps you to put up the scaffold of your new Python project.
5+
Learn more under: https://pyscaffold.org/
86
"""
97
from setuptools import setup
108

src/delayedarray/SparseNdarray.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ def dtype(self) -> numpy.dtype:
119119

120120
@property
121121
def contents(self):
122-
"""Contents of the array.
123-
This is intended to be read-only; in general, ``contents`` should only be modified by developers of
124-
:py:meth:`~delayedarray.interface.extract_sparse_array` methods or creators of new
125-
:py:class:`~delayedarray.DelayedArray.DelayedArray` instances.
122+
"""Contents of the array. This is intended to be read-only; in general,
123+
``contents`` should only be modified by developers of
124+
:py:meth:`~delayedarray.interface.extract_sparse_array` methods or creators of
125+
new :py:class:`~delayedarray.DelayedArray.DelayedArray` instances.
126126
127127
Returns:
128128
A nested list, for a n-dimensional array where n > 1.

src/delayedarray/Subset.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ def is_subset_noop(idx, full):
9696

9797

9898
class Subset:
99-
"""Delayed subset operation.
100-
This will slice the array along one or more dimensions, equivalent to the outer product of
101-
subset indices. The subset can also be used to reduce the dimensionality of the array by
102-
extracting only one element from one or more dimensions.
99+
"""Delayed subset operation. This will slice the array along one or more dimensions,
100+
equivalent to the outer product of subset indices. The subset can also be used to
101+
reduce the dimensionality of the array by extracting only one element from one or
102+
more dimensions.
103103
104104
Attributes:
105105
seed:
@@ -227,8 +227,8 @@ def _extract_dense_array_Subset(x: Subset, idx: Tuple[Sequence, ...]) -> ndarray
227227
if len(not_lost) < len(mappings):
228228
if len(not_lost):
229229
final_shape = []
230-
for l in not_lost:
231-
final_shape.append(len(mappings[l]))
230+
for nl in not_lost:
231+
final_shape.append(len(mappings[nl]))
232232
expanded = expanded.reshape(*final_shape)
233233
else:
234234
idx = [0] * len(mappings)

src/delayedarray/UnaryIsometricOpSimple.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def _choose_operator(op: OP):
4444

4545

4646
class UnaryIsometricOpSimple:
47-
"""Unary isometric operation involving an n-dimensional seed array with no additional arguments.
47+
"""Unary isometric operation involving an n-dimensional seed array with no
48+
additional arguments.
4849
4950
Attributes:
5051
seed: An array-like object.

src/delayedarray/UnaryIsometricOpWithArgs.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ def _choose_operator(op: OP, inplace: bool = False):
5757

5858

5959
class UnaryIsometricOpWithArgs:
60-
"""Unary isometric operation involving an n-dimensional seed array with a scalar or
60+
"""Unary isometric operation involving an n-dimensional seed array with a scalar or
6161
1-dimensional vector.
62-
62+
6363
This is based on Bioconductor's ``DelayedArray::DelayedUnaryIsoOpWithArgs`` class.
6464
Only one n-dimensional array is involved here, hence the "unary" in the name.
6565
66-
The data type of the result is determined by NumPy casting given the ``seed`` and ``value``
67-
data types. We suggest supplying a floating-point ``value`` to avoid unexpected results from
66+
The data type of the result is determined by NumPy casting given the ``seed`` and ``value``
67+
data types. We suggest supplying a floating-point ``value`` to avoid unexpected results from
6868
integer truncation or overflow.
6969
7070
Attributes:
@@ -84,8 +84,8 @@ class UnaryIsometricOpWithArgs:
8484
Ignored for commutative operations in ``op``.
8585
8686
along (int, optional):
87-
Dimension along which the ``value`` is to be added, if ``value`` is a
88-
-dimensional array. This assumes that ``value`` is of length equal to the dimension's
87+
Dimension along which the ``value`` is to be added, if ``value`` is a
88+
-dimensional array. This assumes that ``value`` is of length equal to the dimension's
8989
extent. Ignored if ``value`` is a scalar.
9090
"""
9191

tests/conftest.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
"""
2-
Dummy conftest.py for delayedarray.
1+
"""Dummy conftest.py for delayedarray.
32
4-
If you don't know what this is for, just leave it empty.
5-
Read more about conftest.py under:
6-
- https://docs.pytest.org/en/stable/fixture.html
7-
- https://docs.pytest.org/en/stable/writing_plugins.html
3+
If you don't know what this is for, just leave it empty.
4+
Read more about conftest.py under:
5+
- https://docs.pytest.org/en/stable/fixture.html
6+
- https://docs.pytest.org/en/stable/writing_plugins.html
87
"""
98

109
# import pytest

tests/test_DelayedArray.py

+44-29
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import warnings
2-
import copy
32

43
import delayedarray
5-
import pytest
64
from utils import *
75
import numpy
8-
import math
6+
97

108
def test_DelayedArray_dense():
119
raw = (numpy.random.rand(40, 30) * 5 - 10).astype(numpy.int32)
@@ -146,7 +144,7 @@ def test_DelayedArray_isometric_multiply():
146144

147145
def test_DelayedArray_isometric_divide():
148146
test_shape = (35, 25)
149-
contents = mock_SparseNdarray_contents(test_shape, lower = 1, upper = 10)
147+
contents = mock_SparseNdarray_contents(test_shape, lower=1, upper=10)
150148
y = delayedarray.SparseNdarray(test_shape, contents)
151149
x = delayedarray.DelayedArray(y)
152150
expanded = numpy.array(x)
@@ -179,7 +177,7 @@ def test_DelayedArray_isometric_divide():
179177

180178
def test_DelayedArray_isometric_modulo():
181179
test_shape = (22, 44)
182-
contents = mock_SparseNdarray_contents(test_shape, lower = 1, upper = 10)
180+
contents = mock_SparseNdarray_contents(test_shape, lower=1, upper=10)
183181
y = delayedarray.SparseNdarray(test_shape, contents)
184182
x = delayedarray.DelayedArray(y)
185183
expanded = numpy.array(x)
@@ -250,30 +248,30 @@ def test_DelayedArray_isometric_floordivide():
250248
x = delayedarray.DelayedArray(y)
251249
expanded = numpy.array(x)
252250

253-
z = x ** 2
251+
z = x**2
254252
assert isinstance(z, delayedarray.DelayedArray)
255253
assert delayedarray.is_sparse(z)
256254
assert z.shape == x.shape
257-
assert (numpy.array(z) == expanded ** 2).all()
255+
assert (numpy.array(z) == expanded**2).all()
258256

259-
z = 5 ** x
257+
z = 5**x
260258
assert isinstance(z, delayedarray.DelayedArray)
261259
assert not delayedarray.is_sparse(z)
262260
assert z.shape == x.shape
263-
assert (numpy.array(z) == 5 ** expanded).all()
261+
assert (numpy.array(z) == 5**expanded).all()
264262

265263
v = numpy.random.rand(55)
266-
z = v ** x
264+
z = v**x
267265
assert isinstance(z, delayedarray.DelayedArray)
268266
assert not delayedarray.is_sparse(z)
269267
assert z.shape == x.shape
270-
assert (numpy.array(z) == v ** expanded).all()
268+
assert (numpy.array(z) == v**expanded).all()
271269

272-
z = x ** v
270+
z = x**v
273271
assert isinstance(z, delayedarray.DelayedArray)
274272
assert delayedarray.is_sparse(z)
275273
assert z.shape == x.shape
276-
assert (numpy.array(z) == expanded ** v).all()
274+
assert (numpy.array(z) == expanded**v).all()
277275

278276

279277
def test_DelayedArray_isometric_simple():
@@ -296,15 +294,30 @@ def test_DelayedArray_isometric_simple():
296294
assert (numpy.array(z) == abs(expanded)).all()
297295

298296
for op in [
299-
"log", "log1p", "log2", "log10",
300-
"exp", "expm1",
301-
"sqrt", "abs",
302-
"sin", "cos", "tan",
303-
"sinh", "cosh", "tanh",
304-
"arcsin", "arccos", "arctan",
305-
"arcsinh", "arccosh", "arctanh",
306-
"ceil", "floor", "trunc",
307-
"sign"
297+
"log",
298+
"log1p",
299+
"log2",
300+
"log10",
301+
"exp",
302+
"expm1",
303+
"sqrt",
304+
"abs",
305+
"sin",
306+
"cos",
307+
"tan",
308+
"sinh",
309+
"cosh",
310+
"tanh",
311+
"arcsin",
312+
"arccos",
313+
"arctan",
314+
"arcsinh",
315+
"arccosh",
316+
"arctanh",
317+
"ceil",
318+
"floor",
319+
"trunc",
320+
"sign",
308321
]:
309322
with warnings.catch_warnings():
310323
warnings.simplefilter("ignore")
@@ -331,13 +344,15 @@ def test_DelayedArray_subset():
331344
y = delayedarray.SparseNdarray(test_shape, contents)
332345
x = delayedarray.DelayedArray(y)
333346

334-
sub = x[2,[20,30,40],[10,11,12,13]]
335-
assert sub.shape == (3,4)
347+
sub = x[2, [20, 30, 40], [10, 11, 12, 13]]
348+
assert sub.shape == (3, 4)
336349
assert isinstance(sub._seed, delayedarray.Subset)
337-
assert (numpy.array(sub) == numpy.array(x)[2,:,:][numpy.ix_([20,30,40], [10,11,12,13])]).all()
350+
assert (
351+
numpy.array(sub)
352+
== numpy.array(x)[2, :, :][numpy.ix_([20, 30, 40], [10, 11, 12, 13])]
353+
).all()
338354

339-
sub = x[:,:,range(0, 20, 2)]
340-
assert sub.shape == (30,55,10)
355+
sub = x[:, :, range(0, 20, 2)]
356+
assert sub.shape == (30, 55, 10)
341357
assert isinstance(sub._seed, delayedarray.Subset)
342-
assert (numpy.array(sub) == numpy.array(x)[:,:,range(0, 20, 2)]).all()
343-
358+
assert (numpy.array(sub) == numpy.array(x)[:, :, range(0, 20, 2)]).all()

0 commit comments

Comments
 (0)