Skip to content

Commit 4f3743c

Browse files
authored
Merge pull request #108 from legend-exp/pre-commit-ci-update-config
chore: update pre-commit hooks
2 parents 01546f8 + 73a50fb commit 4f3743c

File tree

11 files changed

+33
-34
lines changed

11 files changed

+33
-34
lines changed

.pre-commit-config.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repos:
1111
additional_dependencies: [black==23.*]
1212

1313
- repo: https://github.com/pre-commit/pre-commit-hooks
14-
rev: "v4.6.0"
14+
rev: "v5.0.0"
1515
hooks:
1616
- id: check-added-large-files
1717
- id: check-case-conflict
@@ -40,7 +40,7 @@ repos:
4040
]
4141

4242
- repo: https://github.com/astral-sh/ruff-pre-commit
43-
rev: "v0.5.0"
43+
rev: "v0.6.9"
4444
hooks:
4545
- id: ruff
4646
args: ["--fix", "--show-fixes"]
@@ -72,12 +72,12 @@ repos:
7272
args: [--prose-wrap=always]
7373

7474
- repo: https://github.com/abravalheri/validate-pyproject
75-
rev: v0.18
75+
rev: v0.20.2
7676
hooks:
7777
- id: validate-pyproject
7878

7979
- repo: https://github.com/python-jsonschema/check-jsonschema
80-
rev: 0.28.6
80+
rev: 0.29.3
8181
hooks:
8282
- id: check-dependabot
8383
- id: check-github-workflows

docs/source/notebooks/DataCompression.ipynb

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
"metadata": {},
1818
"outputs": [],
1919
"source": [
20+
"from __future__ import annotations\n",
21+
"\n",
22+
"import numpy as np\n",
23+
"\n",
2024
"import lgdo\n",
21-
"from lgdo import lh5\n",
22-
"import numpy as np"
25+
"from lgdo import lh5"
2326
]
2427
},
2528
{
@@ -41,7 +44,7 @@
4144
" size=1000,\n",
4245
" col_dict={\n",
4346
" \"col1\": lgdo.Array(np.arange(0, 100, 0.1)),\n",
44-
" \"col2\": lgdo.Array(np.random.rand(1000)),\n",
47+
" \"col2\": lgdo.Array(np.random.default_rng().random(1000)),\n",
4548
" },\n",
4649
")\n",
4750
"data"
@@ -281,7 +284,7 @@
281284
"metadata": {},
282285
"outputs": [],
283286
"source": [
284-
"from lgdo.compression import encode, RadwareSigcompress\n",
287+
"from lgdo.compression import RadwareSigcompress, encode\n",
285288
"\n",
286289
"enc_values = encode(wfs.values, RadwareSigcompress(codec_shift=-32768))\n",
287290
"enc_values"

docs/source/notebooks/LH5Files.ipynb

+7-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"metadata": {},
2828
"outputs": [],
2929
"source": [
30+
"from __future__ import annotations\n",
31+
"\n",
3032
"from legendtestdata import LegendTestData\n",
3133
"\n",
3234
"ldata = LegendTestData()\n",
@@ -210,7 +212,9 @@
210212
"source": [
211213
"from lgdo.lh5 import LH5Store\n",
212214
"\n",
213-
"store = LH5Store(keep_open=True) # with keep_open=True, files are kept open inside the store\n",
215+
"store = LH5Store(\n",
216+
" keep_open=True\n",
217+
") # with keep_open=True, files are kept open inside the store\n",
214218
"store.read(\"geds/raw\", lh5_file) # returns a tuple: (obj, n_rows_read)"
215219
]
216220
},
@@ -456,9 +460,10 @@
456460
"metadata": {},
457461
"outputs": [],
458462
"source": [
459-
"from lgdo import Array, Scalar, WaveformTable\n",
460463
"import numpy as np\n",
461464
"\n",
465+
"from lgdo import Array, Scalar, WaveformTable\n",
466+
"\n",
462467
"rng = np.random.default_rng(12345)\n",
463468
"\n",
464469
"scalar = Scalar(\"made with legend-pydataobj!\")\n",

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ isort.required-imports = ["from __future__ import annotations"]
146146
[tool.ruff.lint.per-file-ignores]
147147
"tests/**" = ["T20"]
148148
"noxfile.py" = ["T20"]
149+
"docs/source/notebooks/*" = ["T201", "E402"]
149150

150151
[tool.pylint]
151152
py-version = "3.8"

src/lgdo/compression/radware.py

+8-16
Original file line numberDiff line numberDiff line change
@@ -441,15 +441,11 @@ def _radware_sigcompress_encode(
441441
while (i < sig_in.size) and (i < j + 48):
442442
si_i = int16(sig_in[i] + shift)
443443
si_im1 = int16(sig_in[i - 1] + shift)
444-
if max1 < si_i:
445-
max1 = si_i
446-
if min1 > si_i:
447-
min1 = si_i
444+
max1 = max(max1, si_i)
445+
min1 = min(min1, si_i)
448446
ds = si_i - si_im1
449-
if max2 < ds:
450-
max2 = ds
451-
if min2 > ds:
452-
min2 = ds
447+
max2 = max(max2, ds)
448+
min2 = min(min2, ds)
453449
nw += 1
454450
i += 1
455451
if max1 - min1 <= max2 - min2: # use absolute values
@@ -460,15 +456,13 @@ def _radware_sigcompress_encode(
460456
i < j + 128
461457
): # FIXME: 128 could be tuned better?
462458
si_i = int16(sig_in[i] + shift)
463-
if max1 < si_i:
464-
max1 = si_i
459+
max1 = max(max1, si_i)
465460
dd1 = max1 - min1
466461
if min1 > si_i:
467462
dd1 = max1 - si_i
468463
if dd1 > mask[nb1]:
469464
break
470-
if min1 > si_i:
471-
min1 = si_i
465+
min1 = min(min1, si_i)
472466
nw += 1
473467
i += 1
474468
else: # use difference values
@@ -481,15 +475,13 @@ def _radware_sigcompress_encode(
481475
si_i = int16(sig_in[i] + shift)
482476
si_im1 = int16(sig_in[i - 1] + shift)
483477
ds = si_i - si_im1
484-
if max2 < ds:
485-
max2 = ds
478+
max2 = max(max2, ds)
486479
dd2 = max2 - min2
487480
if min2 > ds:
488481
dd2 = max2 - ds
489482
if dd2 > mask[nb2]:
490483
break
491-
if min2 > ds:
492-
min2 = ds
484+
min2 = min(min2, ds)
493485
nw += 1
494486
i += 1
495487

src/lgdo/lh5/_serializers/read/composite.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ def _h5_read_lgdo(
103103
if idx is not None:
104104
# check if idx is just an ordered list of the integers if so can ignore
105105
if (idx == np.arange(0, len(idx), 1)).all():
106-
if n_rows > len(idx):
107-
n_rows = len(idx)
106+
n_rows = min(n_rows, len(idx))
108107
idx = None
109108
else:
110109
# chop off indices < start_row

src/lgdo/lh5/_serializers/read/ndarray.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ def _h5_read_ndarray(
5050
n_rows_to_read = len(idx)
5151
else:
5252
n_rows_to_read = ds_n_rows - start_row
53-
if n_rows_to_read > n_rows:
54-
n_rows_to_read = n_rows
53+
n_rows_to_read = min(n_rows_to_read, n_rows)
5554

5655
if idx is None:
5756
fspace.select_hyperslab(

tests/compression/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from lgdo import lh5
66

77

8-
@pytest.fixture()
8+
@pytest.fixture
99
def wftable(lgnd_test_data):
1010
store = lh5.LH5Store()
1111
wft, _ = store.read(

tests/lh5/test_lh5_write.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from lgdo import lh5, types
1212

1313

14-
def test_write_compressed_lgnd_waveform_table(enc_lgnd_file): # noqa: ARG001
14+
def test_write_compressed_lgnd_waveform_table(enc_lgnd_file):
1515
pass
1616

1717

tests/types/test_vectorofvectors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
VovColl = namedtuple("VovColl", ["v2d", "v3d", "v4d"])
1717

1818

19-
@pytest.fixture()
19+
@pytest.fixture
2020
def testvov():
2121
v2d = VectorOfVectors([[1, 2], [3, 4, 5], [2], [4, 8, 9, 7], [5, 3, 1]])
2222
v3d = VectorOfVectors([[[1, 2], [3, 4, 5]], [[2], [4, 8, 9, 7]], [[5, 3, 1]]])

tests/types/test_vovutils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
VovColl = namedtuple("VovColl", ["v2d", "v3d", "v4d"])
1313

1414

15-
@pytest.fixture()
15+
@pytest.fixture
1616
def testvov():
1717
v2d = VectorOfVectors([[1, 2], [3, 4, 5], [2], [4, 8, 9, 7], [5, 3, 1]])
1818
v3d = VectorOfVectors([[[1, 2], [3, 4, 5]], [[2], [4, 8, 9, 7]], [[5, 3, 1]]])

0 commit comments

Comments
 (0)