11from bisect import bisect_left
2- from typing import Callable , Literal , Optional , Sequence , Tuple
2+ from collections .abc import Callable , Sequence
3+ from typing import Literal
34
45import numpy
56from biocutils .package_utils import is_package_installed
@@ -33,14 +34,14 @@ class Hdf5CompressedSparseMatrixSeed:
3334 def __init__ (
3435 self ,
3536 path : str ,
36- group_name : Optional [ str ] ,
37- shape : Tuple [int , int ],
37+ group_name : str | None ,
38+ shape : tuple [int , int ],
3839 by_column : bool ,
39- dtype : Optional [ dtype ] = None ,
40- index_dtype : Optional [ dtype ] = None ,
41- data_name : Optional [ str ] = None ,
42- indices_name : Optional [ str ] = None ,
43- indptr_name : Optional [ str ] = None ,
40+ dtype : dtype | None = None ,
41+ index_dtype : dtype | None = None ,
42+ data_name : str | None = None ,
43+ indices_name : str | None = None ,
44+ indptr_name : str | None = None ,
4445 ):
4546 """
4647 Args:
@@ -140,7 +141,7 @@ def dtype(self) -> dtype:
140141 return self ._dtype
141142
142143 @property
143- def shape (self ) -> Tuple [int , int ]:
144+ def shape (self ) -> tuple [int , int ]:
144145 """
145146 Returns:
146147 Tuple containing the dimensions of this matrix.
@@ -172,7 +173,7 @@ def by_column(self) -> bool:
172173 return self ._by_column
173174
174175 @property
175- def group_name (self ) -> Optional [ str ] :
176+ def group_name (self ) -> str | None :
176177 """
177178 Returns:
178179 Name of the HDF5 group containing the matrix contents, or None if
@@ -277,7 +278,7 @@ def _extract_array(
277278
278279@extract_dense_array .register
279280def extract_dense_array_Hdf5CompressedSparseMatrixSeed (
280- x : Hdf5CompressedSparseMatrixSeed , subset : Tuple [Sequence [int ], ...]
281+ x : Hdf5CompressedSparseMatrixSeed , subset : tuple [Sequence [int ], ...]
281282) -> numpy .ndarray :
282283 """See :py:meth:`~delayedarray.extract_dense_array.extract_dense_array`."""
283284 output = zeros ((len (subset [0 ]), len (subset [1 ])), dtype = x .dtype , order = "F" )
@@ -318,7 +319,7 @@ def _consecutive(r, cols, values):
318319
319320@extract_sparse_array .register
320321def extract_sparse_array_Hdf5CompressedSparseMatrixSeed (
321- x : Hdf5CompressedSparseMatrixSeed , subset : Tuple [Sequence [int ], ...]
322+ x : Hdf5CompressedSparseMatrixSeed , subset : tuple [Sequence [int ], ...]
322323) -> SparseNdarray :
323324 """See :py:meth:`~delayedarray.extract_sparse_array.extract_sparse_array`."""
324325 if x ._by_column :
@@ -390,7 +391,7 @@ def _consecutive(r, cols, values):
390391class Hdf5CompressedSparseMatrix (DelayedArray ):
391392 """Compressed sparse matrix in a HDF5 file as a ``DelayedArray``."""
392393
393- def __init__ (self , path : str , group_name : Optional [ str ] , shape : Tuple [int , int ], by_column : bool , ** kwargs ):
394+ def __init__ (self , path : str , group_name : str | None , shape : tuple [int , int ], by_column : bool , ** kwargs ):
394395 """To construct a ``Hdf5CompressedSparseMatrix`` from an existing :py:class:`~Hdf5CompressedSparseMatrixSeed`,
395396 use :py:meth:`~delayedarray.wrap.wrap` instead.
396397
@@ -417,7 +418,7 @@ def __init__(self, path: str, group_name: Optional[str], shape: Tuple[int, int],
417418 seed = path
418419 else :
419420 seed = Hdf5CompressedSparseMatrixSeed (path , group_name , shape , by_column , ** kwargs )
420- super (Hdf5CompressedSparseMatrix , self ).__init__ (seed )
421+ super ().__init__ (seed )
421422
422423 @property
423424 def path (self ) -> str :
@@ -444,7 +445,7 @@ def by_column(self) -> bool:
444445 return self .seed .by_column
445446
446447 @property
447- def group_name (self ) -> Optional [ str ] :
448+ def group_name (self ) -> str | None :
448449 """
449450 Returns:
450451 Name of the HDF5 group containing the matrix contents, or None if
0 commit comments