Skip to content

Commit 8edd3f9

Browse files
Apply repo-review suggestions (#559)
* Apply repo-review rule PP304 PP304: Sets the log level in pytest log_cli_level should be set. This will allow logs to be displayed on failures. * Apply repo-review rule PP305 PP305: Specifies xfail_strict xfail_strict should be set. You can manually specify if a check should be strict when setting each xfail. * Apply repo-review rules PP306, PP307, PP308 PP306: Specifies strict config --strict-config should be in addopts = [...]. This forces an error if a config setting is misspelled. PP307: Specifies strict markers --strict-markers should be in addopts = [...]. This forces all markers to be specified in config, avoiding misspellings. PP308: Specifies useful pytest summary An explicit summary flag like -ra should be in addopts = [...] (print summary of all fails/errors). * Apply ruff/pygrep-hooks rule PGH004 PGH004 Use specific rule codes when using `noqa` PGH004 Use specific rule codes when using `ruff: noqa` * Apply and enforce ruff rules (RUF) Apply ruff rule RUF012: RUF012 Mutable class attributes should be annotated with `typing.ClassVar` Disable ruff rule RUF001 * Apply and enforce ruff/flake8-bugbear rules (B) B007 Loop control variable not used within loop body B028 No explicit `stacklevel` keyword argument found B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling B905 `zip()` without an explicit `strict=` parameter Co-authored-by: David Stansby <[email protected]> * Apply and enforce ruff/isort rules (I) * Apply repo-review rule PC100 PC100: Has pre-commit-hooks Must have https://github.com/pre-commit/pre-commit-hooks repo in .pre-commit-config.yaml * Enforce repo-review rules * Apply ruff/flake8-implicit-str-concat rules (ISC) ISC001 Implicitly concatenated string literals on one line ISC003 Explicitly concatenated string should be implicitly concatenated * Apply ruff/refurb rules (FURB) FURB163 Prefer `math.log10`/`math.log2` over `math.log` with a redundant base * Fix DeprecationWarning 'pkgutil.find_loader' is deprecated and slated for removal in Python 3.14; use importlib.util.find_spec() instead --------- Co-authored-by: David Stansby <[email protected]>
1 parent 3652eb1 commit 8edd3f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+194
-254
lines changed

.pre-commit-config.yaml

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
exclude: ^fixture/ # files with trailing whitespaces on purpose
12
ci:
23
autoupdate_commit_msg: "chore: update pre-commit hooks"
34
autofix_commit_msg: "style: pre-commit fixes"
@@ -6,9 +7,21 @@ default_stages: [commit, push]
67
default_language_version:
78
python: python3
89
repos:
10+
- repo: https://github.com/pre-commit/pre-commit-hooks
11+
rev: v4.6.0
12+
hooks:
13+
- id: trailing-whitespace
14+
- id: check-yaml
15+
- id: debug-statements
16+
917
- repo: https://github.com/astral-sh/ruff-pre-commit
10-
rev: 'v0.6.9'
18+
rev: v0.6.9
1119
hooks:
1220
- id: ruff
1321
args: ["--fix", "--show-fixes"]
1422
- id: ruff-format
23+
24+
- repo: https://github.com/scientific-python/cookie
25+
rev: 2024.04.23
26+
hooks:
27+
- id: sp-repo-review

.pyup.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# autogenerated pyup.io config file
1+
# autogenerated pyup.io config file
22
# see https://pyup.io/docs/configuration/ for all available options
33

44
schedule: every month

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Numcodecs
22
=========
33

4-
Numcodecs is a Python package providing buffer compression and transformation
4+
Numcodecs is a Python package providing buffer compression and transformation
55
codecs for use in data storage and communication applications.
66

77
.. image:: https://readthedocs.org/projects/numcodecs/badge/?version=latest

adhoc/blosc_memleak_check.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import sys
22

3-
import numcodecs
43
import numpy as np
54
from numpy.testing import assert_array_equal
65

6+
import numcodecs
77

88
codec = numcodecs.Blosc()
99
data = np.arange(int(sys.argv[1]))
10-
for i in range(int(sys.argv[2])):
10+
for _ in range(int(sys.argv[2])):
1111
enc = codec.encode(data)
1212
dec = codec.decode(enc)
1313
arr = np.frombuffer(dec, dtype=data.dtype)

docs/conf.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
# serve to show the default.
1414

1515

16-
import sys
1716
import os
17+
import sys
1818
from unittest.mock import Mock as MagicMock
19+
1920
import numcodecs
2021

2122

notebooks/benchmark_vlen.ipynb

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
],
2626
"source": [
2727
"import numpy as np\n",
28+
"\n",
2829
"import numcodecs\n",
2930
"\n",
3031
"numcodecs.__version__"

numcodecs/__init__.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# flake8: noqa
1+
# ruff: noqa: E402,F401
22
"""Numcodecs is a Python package providing buffer compression and
33
transformation codecs for use in data storage and communication
44
applications. These include:
@@ -17,14 +17,12 @@
1717
1818
"""
1919

20-
import multiprocessing
2120
import atexit
21+
import multiprocessing
2222
from contextlib import suppress
2323

24-
25-
from numcodecs.version import version as __version__
2624
from numcodecs.registry import get_codec, register_codec
27-
25+
from numcodecs.version import version as __version__
2826
from numcodecs.zlib import Zlib
2927

3028
register_codec(Zlib)
@@ -130,7 +128,7 @@
130128

131129
with suppress(ImportError):
132130
from numcodecs import vlen
133-
from numcodecs.vlen import VLenUTF8, VLenBytes, VLenArray
131+
from numcodecs.vlen import VLenArray, VLenBytes, VLenUTF8
134132

135133
register_codec(VLenUTF8)
136134
register_codec(VLenBytes)

numcodecs/astype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22

33
from .abc import Codec
4-
from .compat import ndarray_copy, ensure_ndarray
4+
from .compat import ensure_ndarray, ndarray_copy
55

66

77
class AsType(Codec):

numcodecs/bitround.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import numpy as np
22

3-
43
from .abc import Codec
54
from .compat import ensure_ndarray_like, ndarray_copy
65

numcodecs/blosc.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def decompress_partial(source, start, nitems, dest=None):
468468
raise RuntimeError('error during blosc partial decompression: %d', ret)
469469

470470
return dest
471-
471+
472472

473473
# set the value of this variable to True or False to override the
474474
# default adaptive behaviour

numcodecs/bz2.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import bz2 as _bz2
22

3-
43
from numcodecs.abc import Codec
5-
from numcodecs.compat import ndarray_copy, ensure_contiguous_ndarray
4+
from numcodecs.compat import ensure_contiguous_ndarray, ndarray_copy
65

76

87
class BZ2(Codec):

numcodecs/categorize.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from .abc import Codec
2-
from .compat import ensure_ndarray, ndarray_copy, ensure_text
3-
4-
51
import numpy as np
62

3+
from .abc import Codec
4+
from .compat import ensure_ndarray, ensure_text, ndarray_copy
5+
76

87
class Categorize(Codec):
98
"""Filter encoding categorical string data as integers.
@@ -41,7 +40,7 @@ class Categorize(Codec):
4140
def __init__(self, labels, dtype, astype='u1'):
4241
self.dtype = np.dtype(dtype)
4342
if self.dtype.kind not in 'UO':
44-
raise TypeError("only unicode ('U') and object ('O') dtypes are " "supported")
43+
raise TypeError("only unicode ('U') and object ('O') dtypes are supported")
4544
self.labels = [ensure_text(label) for label in labels]
4645
self.astype = np.dtype(astype)
4746
if self.astype == np.dtype(object):

numcodecs/checksum32.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1+
import struct
12
import zlib
23

3-
44
import numpy as np
5-
import struct
6-
75

86
from .abc import Codec
97
from .compat import ensure_contiguous_ndarray, ndarray_copy

numcodecs/compat.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# flake8: noqa
2-
import functools
3-
import codecs
1+
# ruff: noqa: F401
42
import array
3+
import codecs
4+
import functools
55

66
import numpy as np
77

numcodecs/delta.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import numpy as np
22

3-
43
from .abc import Codec
54
from .compat import ensure_ndarray, ndarray_copy
65

numcodecs/fixedscaleoffset.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import numpy as np
22

3-
43
from .abc import Codec
54
from .compat import ensure_ndarray, ndarray_copy
65

numcodecs/jenkins.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ cpdef uint32_t jenkins_lookup3(const uint8_t[::1] _data, uint32_t initval=0):
168168
if length == 12:
169169
c += (<uint32_t>k[11]) << 24
170170
length -= 1
171-
171+
172172
if length == 11:
173173
c += (<uint32_t>k[10]) << 16
174174
length -= 1
@@ -231,7 +231,7 @@ cdef inline uint32_t _jenkins_lookup3_final(uint32_t a, uint32_t b, uint32_t c):
231231
the output delta to a Gray code (a^(a>>1)) so a string of 1's (as
232232
is commonly produced by subtraction) look like a single 1-bit
233233
difference.
234-
* the base values were pseudorandom, all zero but one bit set, or
234+
* the base values were pseudorandom, all zero but one bit set, or
235235
all zero plus a counter that starts at zero.
236236
237237
These constants passed:
@@ -279,7 +279,7 @@ cdef inline (uint32_t, uint32_t, uint32_t) _jenkins_lookup3_mix(uint32_t a, uint
279279
the output delta to a Gray code (a^(a>>1)) so a string of 1's (as
280280
is commonly produced by subtraction) look like a single 1-bit
281281
difference.
282-
* the base values were pseudorandom, all zero but one bit set, or
282+
* the base values were pseudorandom, all zero but one bit set, or
283283
all zero plus a counter that starts at zero.
284284
285285
Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that
@@ -289,7 +289,7 @@ cdef inline (uint32_t, uint32_t, uint32_t) _jenkins_lookup3_mix(uint32_t a, uint
289289
14 9 3 7 17 3
290290
Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing
291291
for "differ" defined as + with a one-bit base and a two-bit delta. I
292-
used http://burtleburtle.net/bob/hash/avalanche.html to choose
292+
used http://burtleburtle.net/bob/hash/avalanche.html to choose
293293
the operations, constants, and arrangements of the variables.
294294
295295
This does not achieve avalanche. There are input bits of (a,b,c)

numcodecs/json.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import json as _json
22
import textwrap
33

4-
54
import numpy as np
65

7-
86
from .abc import Codec
97
from .compat import ensure_text
108

numcodecs/lzma.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
if _lzma:
1212
from .abc import Codec
13-
from .compat import ndarray_copy, ensure_contiguous_ndarray
13+
from .compat import ensure_contiguous_ndarray, ndarray_copy
1414

1515
# noinspection PyShadowingBuiltins
1616
class LZMA(Codec):

numcodecs/msgpacks.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import numpy as np
21
import msgpack
3-
2+
import numpy as np
43

54
from .abc import Codec
65
from .compat import ensure_contiguous_ndarray

numcodecs/ndarray_like.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Optional, Protocol, runtime_checkable
1+
from typing import Any, ClassVar, Optional, Protocol, runtime_checkable
22

33

44
class _CachedProtocolMeta(Protocol.__class__):
@@ -11,7 +11,7 @@ class _CachedProtocolMeta(Protocol.__class__):
1111
isinstance checks using the object's class as the cache key.
1212
"""
1313

14-
_instancecheck_cache: dict[tuple[type, type], bool] = {}
14+
_instancecheck_cache: ClassVar[dict[tuple[type, type], bool]] = {}
1515

1616
def __instancecheck__(self, instance):
1717
key = (self, instance.__class__)

numcodecs/packbits.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import numpy as np
22

3-
43
from .abc import Codec
54
from .compat import ensure_ndarray, ndarray_copy
65

numcodecs/pcodec.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from typing import Optional, Literal
1+
from typing import Literal, Optional
22

33
import numcodecs
44
import numcodecs.abc
55
from numcodecs.compat import ensure_contiguous_ndarray
66

77
try:
8-
from pcodec import standalone, ChunkConfig, PagingSpec, ModeSpec
8+
from pcodec import ChunkConfig, ModeSpec, PagingSpec, standalone
99
except ImportError: # pragma: no cover
1010
standalone = None
1111

numcodecs/quantize.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import math
22

3-
43
import numpy as np
54

6-
75
from .abc import Codec
86
from .compat import ensure_ndarray, ndarray_copy
97

@@ -65,12 +63,12 @@ def encode(self, buf):
6563

6664
# apply scaling
6765
precision = 10.0**-self.digits
68-
exp = math.log(precision, 10)
66+
exp = math.log10(precision)
6967
if exp < 0:
7068
exp = int(math.floor(exp))
7169
else:
7270
exp = int(math.ceil(exp))
73-
bits = math.ceil(math.log(10.0**-exp, 2))
71+
bits = math.ceil(math.log2(10.0**-exp))
7472
scale = 2.0**bits
7573
enc = np.around(scale * arr) / scale
7674

numcodecs/registry.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""The registry module provides some simple convenience functions to enable
22
applications to dynamically register and look-up codec classes."""
33

4-
from importlib.metadata import entry_points
54
import logging
5+
from importlib.metadata import entry_points
66

77
logger = logging.getLogger("numcodecs")
88
codec_registry = {}

numcodecs/shuffle.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import numpy as np
2-
from .compat import ensure_contiguous_ndarray
3-
from .abc import Codec
2+
43
from ._shuffle import _doShuffle, _doUnshuffle
4+
from .abc import Codec
5+
from .compat import ensure_contiguous_ndarray
56

67

78
class Shuffle(Codec):

numcodecs/tests/common.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33
import os
44
from glob import glob
55

6-
76
import numpy as np
8-
from numpy.testing import assert_array_almost_equal, assert_array_equal
97
import pytest
8+
from numpy.testing import assert_array_almost_equal, assert_array_equal
109

11-
10+
# star import needed for repr tests so eval finds names
11+
from numcodecs import * # noqa: F403
1212
from numcodecs.compat import ensure_bytes, ensure_ndarray
1313
from numcodecs.registry import get_codec
1414

15-
# star import needed for repr tests so eval finds names
16-
from numcodecs import * # noqa
17-
18-
1915
greetings = [
2016
'¡Hola mundo!',
2117
'Hej Världen!',
@@ -200,7 +196,7 @@ def assert_array_items_equal(res, arr):
200196
# and values
201197
arr = arr.ravel().tolist()
202198
res = res.ravel().tolist()
203-
for a, r in zip(arr, res):
199+
for a, r in zip(arr, res, strict=True):
204200
if isinstance(a, np.ndarray):
205201
assert_array_equal(a, r)
206202
elif a != a:

0 commit comments

Comments
 (0)