From 852d0f5b786852427d9cc120ed8d715edadaf42d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 31 Aug 2026 16:31:57 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.15.6 → v0.16.5](https://github.com/astral-sh/ruff-pre-commit/compare/v0.15.6...v0.16.5) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f91485..7135fec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,7 +33,7 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.15.6 + rev: v0.16.5 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From 73d2a7e07a3abd1c0578c6fd25a45c68268c4884 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 31 Aug 2026 16:33:14 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- README.md | 12 +++---- setup.py | 2 +- .../Hdf5CompressedSparseMatrixSeed.py | 31 ++++++++++--------- src/hdf5array/Hdf5DenseArraySeed.py | 10 +++--- src/hdf5array/__init__.py | 2 +- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 4c83bf3..166ba29 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,11 @@ Let's mock up a dense array: ```python import numpy + data = numpy.random.rand(40, 50, 100) import h5py + with h5py.File("whee.h5", "w") as handle: handle.create_dataset("yay", data=data) ``` @@ -48,6 +50,7 @@ We can now represent it as a `Hdf5DenseArray`: ```python import hdf5array + arr = hdf5array.Hdf5DenseArray("whee.h5", "yay", native_order=True) ## <40 x 50 x 100> Hdf5DenseArray object of type 'float64' ## [[[0.63008796, 0.34849183, 0.75621679, ..., 0.07343495, 0.63095765, @@ -85,6 +88,7 @@ To demonstrate, let's mock up some sparse data using **scipy**: ```python import scipy.sparse + mock = scipy.sparse.random(1000, 200, 0.1).tocsc() with h5py.File("sparse_whee.h5", "w") as handle: @@ -99,12 +103,8 @@ The constructor will not do any auto-detection so we need to provide this inform ```python import hdf5array -arr = hdf5array.Hdf5CompressedSparseMatrix( - "sparse_whee.h5", - "sparse_blah", - shape=(100, 200), - by_column=True -) + +arr = hdf5array.Hdf5CompressedSparseMatrix("sparse_whee.h5", "sparse_blah", shape=(100, 200), by_column=True) ## <100 x 200> sparse Hdf5CompressedSparseMatrix object of type 'float64' ## [[0. , 0. , 0.26563417, ..., 0. , 0. , ## 0. ], diff --git a/setup.py b/setup.py index 1e5d407..a81557d 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ if __name__ == "__main__": try: setup(use_scm_version={"version_scheme": "no-guess-dev"}) - except: # noqa + except: print( "\n\nAn error occurred while building the project, " "please ensure you have the most updated version of setuptools, " diff --git a/src/hdf5array/Hdf5CompressedSparseMatrixSeed.py b/src/hdf5array/Hdf5CompressedSparseMatrixSeed.py index ba331cd..c23536a 100644 --- a/src/hdf5array/Hdf5CompressedSparseMatrixSeed.py +++ b/src/hdf5array/Hdf5CompressedSparseMatrixSeed.py @@ -1,5 +1,6 @@ from bisect import bisect_left -from typing import Callable, Literal, Optional, Sequence, Tuple +from collections.abc import Callable, Sequence +from typing import Literal import numpy from biocutils.package_utils import is_package_installed @@ -33,14 +34,14 @@ class Hdf5CompressedSparseMatrixSeed: def __init__( self, path: str, - group_name: Optional[str], - shape: Tuple[int, int], + group_name: str | None, + shape: tuple[int, int], by_column: bool, - dtype: Optional[dtype] = None, - index_dtype: Optional[dtype] = None, - data_name: Optional[str] = None, - indices_name: Optional[str] = None, - indptr_name: Optional[str] = None, + dtype: dtype | None = None, + index_dtype: dtype | None = None, + data_name: str | None = None, + indices_name: str | None = None, + indptr_name: str | None = None, ): """ Args: @@ -140,7 +141,7 @@ def dtype(self) -> dtype: return self._dtype @property - def shape(self) -> Tuple[int, int]: + def shape(self) -> tuple[int, int]: """ Returns: Tuple containing the dimensions of this matrix. @@ -172,7 +173,7 @@ def by_column(self) -> bool: return self._by_column @property - def group_name(self) -> Optional[str]: + def group_name(self) -> str | None: """ Returns: Name of the HDF5 group containing the matrix contents, or None if @@ -277,7 +278,7 @@ def _extract_array( @extract_dense_array.register def extract_dense_array_Hdf5CompressedSparseMatrixSeed( - x: Hdf5CompressedSparseMatrixSeed, subset: Tuple[Sequence[int], ...] + x: Hdf5CompressedSparseMatrixSeed, subset: tuple[Sequence[int], ...] ) -> numpy.ndarray: """See :py:meth:`~delayedarray.extract_dense_array.extract_dense_array`.""" output = zeros((len(subset[0]), len(subset[1])), dtype=x.dtype, order="F") @@ -318,7 +319,7 @@ def _consecutive(r, cols, values): @extract_sparse_array.register def extract_sparse_array_Hdf5CompressedSparseMatrixSeed( - x: Hdf5CompressedSparseMatrixSeed, subset: Tuple[Sequence[int], ...] + x: Hdf5CompressedSparseMatrixSeed, subset: tuple[Sequence[int], ...] ) -> SparseNdarray: """See :py:meth:`~delayedarray.extract_sparse_array.extract_sparse_array`.""" if x._by_column: @@ -390,7 +391,7 @@ def _consecutive(r, cols, values): class Hdf5CompressedSparseMatrix(DelayedArray): """Compressed sparse matrix in a HDF5 file as a ``DelayedArray``.""" - def __init__(self, path: str, group_name: Optional[str], shape: Tuple[int, int], by_column: bool, **kwargs): + def __init__(self, path: str, group_name: str | None, shape: tuple[int, int], by_column: bool, **kwargs): """To construct a ``Hdf5CompressedSparseMatrix`` from an existing :py:class:`~Hdf5CompressedSparseMatrixSeed`, use :py:meth:`~delayedarray.wrap.wrap` instead. @@ -417,7 +418,7 @@ def __init__(self, path: str, group_name: Optional[str], shape: Tuple[int, int], seed = path else: seed = Hdf5CompressedSparseMatrixSeed(path, group_name, shape, by_column, **kwargs) - super(Hdf5CompressedSparseMatrix, self).__init__(seed) + super().__init__(seed) @property def path(self) -> str: @@ -444,7 +445,7 @@ def by_column(self) -> bool: return self.seed.by_column @property - def group_name(self) -> Optional[str]: + def group_name(self) -> str | None: """ Returns: Name of the HDF5 group containing the matrix contents, or None if diff --git a/src/hdf5array/Hdf5DenseArraySeed.py b/src/hdf5array/Hdf5DenseArraySeed.py index 22a3c46..fd14133 100644 --- a/src/hdf5array/Hdf5DenseArraySeed.py +++ b/src/hdf5array/Hdf5DenseArraySeed.py @@ -1,4 +1,4 @@ -from typing import Optional, Sequence, Tuple +from collections.abc import Sequence import numpy from delayedarray import ( @@ -24,7 +24,7 @@ def __init__( self, path: str, name: str, - dtype: Optional[dtype] = None, + dtype: dtype | None = None, native_order: bool = False, ) -> None: """ @@ -88,7 +88,7 @@ def dtype(self) -> dtype: return self._dtype @property - def shape(self) -> Tuple[int, ...]: + def shape(self) -> tuple[int, ...]: """ Returns: Tuple containing the dimensions of this array. @@ -122,7 +122,7 @@ def chunk_grid_Hdf5DenseArraySeed(x: Hdf5DenseArraySeed): @extract_dense_array.register -def extract_dense_array_Hdf5DenseArraySeed(x: Hdf5DenseArraySeed, subset: Tuple[Sequence[int], ...]) -> numpy.ndarray: +def extract_dense_array_Hdf5DenseArraySeed(x: Hdf5DenseArraySeed, subset: tuple[Sequence[int], ...]) -> numpy.ndarray: """See :py:meth:`~delayedarray.extract_dense_array.extract_dense_array`.""" converted = [] num_lists = 0 @@ -204,7 +204,7 @@ def __init__(self, path: str, name: str, **kwargs): seed = path else: seed = Hdf5DenseArraySeed(path, name, **kwargs) - super(Hdf5DenseArray, self).__init__(seed) + super().__init__(seed) @property def path(self) -> str: diff --git a/src/hdf5array/__init__.py b/src/hdf5array/__init__.py index 697004c..7492bd4 100644 --- a/src/hdf5array/__init__.py +++ b/src/hdf5array/__init__.py @@ -16,5 +16,5 @@ del version, PackageNotFoundError -from .Hdf5DenseArraySeed import Hdf5DenseArray, Hdf5DenseArraySeed from .Hdf5CompressedSparseMatrixSeed import Hdf5CompressedSparseMatrix, Hdf5CompressedSparseMatrixSeed +from .Hdf5DenseArraySeed import Hdf5DenseArray, Hdf5DenseArraySeed