Skip to content

Commit

Permalink
Merge pull request #108 from legend-exp/pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
chore: update pre-commit hooks
  • Loading branch information
iguinn authored Nov 1, 2024
2 parents 01546f8 + 73a50fb commit 4f3743c
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 34 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
additional_dependencies: [black==23.*]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.6.0"
rev: "v5.0.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand Down Expand Up @@ -40,7 +40,7 @@ repos:
]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.5.0"
rev: "v0.6.9"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand Down Expand Up @@ -72,12 +72,12 @@ repos:
args: [--prose-wrap=always]

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.18
rev: v0.20.2
hooks:
- id: validate-pyproject

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.6
rev: 0.29.3
hooks:
- id: check-dependabot
- id: check-github-workflows
Expand Down
11 changes: 7 additions & 4 deletions docs/source/notebooks/DataCompression.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
"metadata": {},
"outputs": [],
"source": [
"from __future__ import annotations\n",
"\n",
"import numpy as np\n",
"\n",
"import lgdo\n",
"from lgdo import lh5\n",
"import numpy as np"
"from lgdo import lh5"
]
},
{
Expand All @@ -41,7 +44,7 @@
" size=1000,\n",
" col_dict={\n",
" \"col1\": lgdo.Array(np.arange(0, 100, 0.1)),\n",
" \"col2\": lgdo.Array(np.random.rand(1000)),\n",
" \"col2\": lgdo.Array(np.random.default_rng().random(1000)),\n",
" },\n",
")\n",
"data"
Expand Down Expand Up @@ -281,7 +284,7 @@
"metadata": {},
"outputs": [],
"source": [
"from lgdo.compression import encode, RadwareSigcompress\n",
"from lgdo.compression import RadwareSigcompress, encode\n",
"\n",
"enc_values = encode(wfs.values, RadwareSigcompress(codec_shift=-32768))\n",
"enc_values"
Expand Down
9 changes: 7 additions & 2 deletions docs/source/notebooks/LH5Files.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"metadata": {},
"outputs": [],
"source": [
"from __future__ import annotations\n",
"\n",
"from legendtestdata import LegendTestData\n",
"\n",
"ldata = LegendTestData()\n",
Expand Down Expand Up @@ -210,7 +212,9 @@
"source": [
"from lgdo.lh5 import LH5Store\n",
"\n",
"store = LH5Store(keep_open=True) # with keep_open=True, files are kept open inside the store\n",
"store = LH5Store(\n",
" keep_open=True\n",
") # with keep_open=True, files are kept open inside the store\n",
"store.read(\"geds/raw\", lh5_file) # returns a tuple: (obj, n_rows_read)"
]
},
Expand Down Expand Up @@ -456,9 +460,10 @@
"metadata": {},
"outputs": [],
"source": [
"from lgdo import Array, Scalar, WaveformTable\n",
"import numpy as np\n",
"\n",
"from lgdo import Array, Scalar, WaveformTable\n",
"\n",
"rng = np.random.default_rng(12345)\n",
"\n",
"scalar = Scalar(\"made with legend-pydataobj!\")\n",
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ isort.required-imports = ["from __future__ import annotations"]
[tool.ruff.lint.per-file-ignores]
"tests/**" = ["T20"]
"noxfile.py" = ["T20"]
"docs/source/notebooks/*" = ["T201", "E402"]

[tool.pylint]
py-version = "3.8"
Expand Down
24 changes: 8 additions & 16 deletions src/lgdo/compression/radware.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,11 @@ def _radware_sigcompress_encode(
while (i < sig_in.size) and (i < j + 48):
si_i = int16(sig_in[i] + shift)
si_im1 = int16(sig_in[i - 1] + shift)
if max1 < si_i:
max1 = si_i
if min1 > si_i:
min1 = si_i
max1 = max(max1, si_i)
min1 = min(min1, si_i)
ds = si_i - si_im1
if max2 < ds:
max2 = ds
if min2 > ds:
min2 = ds
max2 = max(max2, ds)
min2 = min(min2, ds)
nw += 1
i += 1
if max1 - min1 <= max2 - min2: # use absolute values
Expand All @@ -460,15 +456,13 @@ def _radware_sigcompress_encode(
i < j + 128
): # FIXME: 128 could be tuned better?
si_i = int16(sig_in[i] + shift)
if max1 < si_i:
max1 = si_i
max1 = max(max1, si_i)
dd1 = max1 - min1
if min1 > si_i:
dd1 = max1 - si_i
if dd1 > mask[nb1]:
break
if min1 > si_i:
min1 = si_i
min1 = min(min1, si_i)
nw += 1
i += 1
else: # use difference values
Expand All @@ -481,15 +475,13 @@ def _radware_sigcompress_encode(
si_i = int16(sig_in[i] + shift)
si_im1 = int16(sig_in[i - 1] + shift)
ds = si_i - si_im1
if max2 < ds:
max2 = ds
max2 = max(max2, ds)
dd2 = max2 - min2
if min2 > ds:
dd2 = max2 - ds
if dd2 > mask[nb2]:
break
if min2 > ds:
min2 = ds
min2 = min(min2, ds)
nw += 1
i += 1

Expand Down
3 changes: 1 addition & 2 deletions src/lgdo/lh5/_serializers/read/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ def _h5_read_lgdo(
if idx is not None:
# check if idx is just an ordered list of the integers if so can ignore
if (idx == np.arange(0, len(idx), 1)).all():
if n_rows > len(idx):
n_rows = len(idx)
n_rows = min(n_rows, len(idx))
idx = None
else:
# chop off indices < start_row
Expand Down
3 changes: 1 addition & 2 deletions src/lgdo/lh5/_serializers/read/ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def _h5_read_ndarray(
n_rows_to_read = len(idx)
else:
n_rows_to_read = ds_n_rows - start_row
if n_rows_to_read > n_rows:
n_rows_to_read = n_rows
n_rows_to_read = min(n_rows_to_read, n_rows)

if idx is None:
fspace.select_hyperslab(
Expand Down
2 changes: 1 addition & 1 deletion tests/compression/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from lgdo import lh5


@pytest.fixture()
@pytest.fixture
def wftable(lgnd_test_data):
store = lh5.LH5Store()
wft, _ = store.read(
Expand Down
2 changes: 1 addition & 1 deletion tests/lh5/test_lh5_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from lgdo import lh5, types


def test_write_compressed_lgnd_waveform_table(enc_lgnd_file): # noqa: ARG001
def test_write_compressed_lgnd_waveform_table(enc_lgnd_file):
pass


Expand Down
2 changes: 1 addition & 1 deletion tests/types/test_vectorofvectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
VovColl = namedtuple("VovColl", ["v2d", "v3d", "v4d"])


@pytest.fixture()
@pytest.fixture
def testvov():
v2d = VectorOfVectors([[1, 2], [3, 4, 5], [2], [4, 8, 9, 7], [5, 3, 1]])
v3d = VectorOfVectors([[[1, 2], [3, 4, 5]], [[2], [4, 8, 9, 7]], [[5, 3, 1]]])
Expand Down
2 changes: 1 addition & 1 deletion tests/types/test_vovutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
VovColl = namedtuple("VovColl", ["v2d", "v3d", "v4d"])


@pytest.fixture()
@pytest.fixture
def testvov():
v2d = VectorOfVectors([[1, 2], [3, 4, 5], [2], [4, 8, 9, 7], [5, 3, 1]])
v3d = VectorOfVectors([[[1, 2], [3, 4, 5]], [[2], [4, 8, 9, 7]], [[5, 3, 1]]])
Expand Down

0 comments on commit 4f3743c

Please sign in to comment.