From 91253476766505eaae88f2d82e5e7be9643ad9ce Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:22:50 +0000 Subject: [PATCH 1/4] chore: update pre-commit hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.6.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.6.0...v5.0.0) - [github.com/astral-sh/ruff-pre-commit: v0.5.0 → v0.6.9](https://github.com/astral-sh/ruff-pre-commit/compare/v0.5.0...v0.6.9) - [github.com/abravalheri/validate-pyproject: v0.18 → v0.20.2](https://github.com/abravalheri/validate-pyproject/compare/v0.18...v0.20.2) - [github.com/python-jsonschema/check-jsonschema: 0.28.6 → 0.29.3](https://github.com/python-jsonschema/check-jsonschema/compare/0.28.6...0.29.3) --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 75a10d19..098c6376 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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"] @@ -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 From bb4f6f9a6ca43119496b91936930320f8924a34b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:23:41 +0000 Subject: [PATCH 2/4] style: pre-commit fixes --- docs/source/notebooks/DataCompression.ipynb | 9 +++++--- docs/source/notebooks/LH5Files.ipynb | 9 ++++++-- src/lgdo/compression/radware.py | 24 +++++++-------------- src/lgdo/lh5/_serializers/read/composite.py | 3 +-- src/lgdo/lh5/_serializers/read/ndarray.py | 3 +-- tests/compression/conftest.py | 2 +- tests/lh5/test_lh5_write.py | 2 +- tests/types/test_vectorofvectors.py | 2 +- tests/types/test_vovutils.py | 2 +- 9 files changed, 27 insertions(+), 29 deletions(-) diff --git a/docs/source/notebooks/DataCompression.ipynb b/docs/source/notebooks/DataCompression.ipynb index b4c518b5..06d2ed4d 100644 --- a/docs/source/notebooks/DataCompression.ipynb +++ b/docs/source/notebooks/DataCompression.ipynb @@ -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" ] }, { @@ -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" diff --git a/docs/source/notebooks/LH5Files.ipynb b/docs/source/notebooks/LH5Files.ipynb index 7cb97cf3..3da13d2a 100644 --- a/docs/source/notebooks/LH5Files.ipynb +++ b/docs/source/notebooks/LH5Files.ipynb @@ -27,6 +27,8 @@ "metadata": {}, "outputs": [], "source": [ + "from __future__ import annotations\n", + "\n", "from legendtestdata import LegendTestData\n", "\n", "ldata = LegendTestData()\n", @@ -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)" ] }, @@ -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", diff --git a/src/lgdo/compression/radware.py b/src/lgdo/compression/radware.py index 5dcc5a49..4c641639 100644 --- a/src/lgdo/compression/radware.py +++ b/src/lgdo/compression/radware.py @@ -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 @@ -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 @@ -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 diff --git a/src/lgdo/lh5/_serializers/read/composite.py b/src/lgdo/lh5/_serializers/read/composite.py index 2674499e..5041c321 100644 --- a/src/lgdo/lh5/_serializers/read/composite.py +++ b/src/lgdo/lh5/_serializers/read/composite.py @@ -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 diff --git a/src/lgdo/lh5/_serializers/read/ndarray.py b/src/lgdo/lh5/_serializers/read/ndarray.py index 157edd49..dab02400 100644 --- a/src/lgdo/lh5/_serializers/read/ndarray.py +++ b/src/lgdo/lh5/_serializers/read/ndarray.py @@ -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( diff --git a/tests/compression/conftest.py b/tests/compression/conftest.py index a2451579..6807d81d 100644 --- a/tests/compression/conftest.py +++ b/tests/compression/conftest.py @@ -5,7 +5,7 @@ from lgdo import lh5 -@pytest.fixture() +@pytest.fixture def wftable(lgnd_test_data): store = lh5.LH5Store() wft, _ = store.read( diff --git a/tests/lh5/test_lh5_write.py b/tests/lh5/test_lh5_write.py index fd9604d4..2333d282 100644 --- a/tests/lh5/test_lh5_write.py +++ b/tests/lh5/test_lh5_write.py @@ -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 diff --git a/tests/types/test_vectorofvectors.py b/tests/types/test_vectorofvectors.py index 0948c7bc..722ba941 100644 --- a/tests/types/test_vectorofvectors.py +++ b/tests/types/test_vectorofvectors.py @@ -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]]]) diff --git a/tests/types/test_vovutils.py b/tests/types/test_vovutils.py index e5baa43a..883f9d9d 100644 --- a/tests/types/test_vovutils.py +++ b/tests/types/test_vovutils.py @@ -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]]]) From 7b854d7bef147a15d19fd6c44a408fab6af1af0b Mon Sep 17 00:00:00 2001 From: iguinn Date: Fri, 1 Nov 2024 10:00:46 -0700 Subject: [PATCH 3/4] Pre-commit stuff --- docs/source/notebooks/DataCompression.ipynb | 2 +- pyproject.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/notebooks/DataCompression.ipynb b/docs/source/notebooks/DataCompression.ipynb index 06d2ed4d..2f82f233 100644 --- a/docs/source/notebooks/DataCompression.ipynb +++ b/docs/source/notebooks/DataCompression.ipynb @@ -44,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" diff --git a/pyproject.toml b/pyproject.toml index 63ca9f77..b26f7a77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" From 73a50fb2e8e8088a3b557aa97676442c0368b3b2 Mon Sep 17 00:00:00 2001 From: iguinn Date: Fri, 1 Nov 2024 10:03:53 -0700 Subject: [PATCH 4/4] Another try at pre-commit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b26f7a77..466d3d77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -146,7 +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"] +"docs/source/notebooks/*" = ["T201", "E402"] [tool.pylint] py-version = "3.8"