@@ -570,6 +570,9 @@ def __eq__(self, other):
570570 and (self .end == other .end )
571571 )
572572
573+ def __repr__ (self ):
574+ return f"Region({ self ._contig !r} , { self ._start !r} , { self ._end !r} )"
575+
573576 def __str__ (self ):
574577 out = self ._contig
575578 if self ._start is not None or self ._end is not None :
@@ -897,14 +900,50 @@ def _hash_params(params):
897900 return h , s
898901
899902
900- def _jitter (a , fraction ):
901- """Jitter data in `a` using the fraction `f`."""
903+ def _jitter (a , fraction , random_state = np .random ):
904+ """Jitter data by adding uniform noise scaled by the data range.
905+
906+ Parameters
907+ ----------
908+ a : array-like
909+ Input data to jitter. Can be a numpy array or pandas Series.
910+ fraction : float
911+ Controls the amplitude of the jitter relative to the data range.
912+ random_state : numpy.random.Generator or module, optional
913+ Random number generator to use. Accepts a ``numpy.random.Generator``
914+ (from ``np.random.default_rng()``) or the ``numpy.random`` module.
915+ Defaults to ``np.random`` (global RNG) for backward compatibility.
916+
917+ Returns
918+ -------
919+ array-like
920+ Jittered copy of the input data with the same shape and type.
921+
922+ Notes
923+ -----
924+ Prefer passing a local ``np.random.default_rng(seed=...)`` to avoid
925+ mutating global RNG state and to ensure reproducibility.
926+
927+ """
902928 r = a .max () - a .min ()
903- return a + fraction * np . random .uniform (- r , r , a .shape )
929+ return a + fraction * random_state .uniform (- r , r , a .shape )
904930
905931
906932class CacheMiss (Exception ):
907- pass
933+ """Raised when a requested item is not present in the cache."""
934+
935+ def __init__ (self , key = None ):
936+ self .key = key
937+ if key is not None :
938+ message = f"Cache miss for key: { key !r} "
939+ else :
940+ message = "Cache miss: requested item not found in cache."
941+ super ().__init__ (message )
942+
943+ def __repr__ (self ):
944+ if self .key is not None :
945+ return f"CacheMiss({ self .key !r} )"
946+ return "CacheMiss()"
908947
909948
910949class LoggingHelper :
@@ -1508,12 +1547,10 @@ def _apply_allele_mapping(x, mapping, max_allele):
15081547
15091548def _dask_apply_allele_mapping (v , mapping , max_allele ):
15101549 if not isinstance (v , da .Array ):
1511- raise TypeError (
1512- f"Expected v to be a dask.array.Array, " f"got { type (v ).__name__ } "
1513- )
1550+ raise TypeError (f"Expected v to be a dask.array.Array, got { type (v ).__name__ } " )
15141551 if not isinstance (mapping , np .ndarray ):
15151552 raise TypeError (
1516- f"Expected mapping to be a numpy.ndarray, " f" got { type (mapping ).__name__ } "
1553+ f"Expected mapping to be a numpy.ndarray, got { type (mapping ).__name__ } "
15171554 )
15181555 assert v .ndim == 2
15191556 assert mapping .ndim == 2
@@ -1535,12 +1572,10 @@ def _genotype_array_map_alleles(gt, mapping):
15351572 # N.B., scikit-allel does not handle empty blocks well, so we
15361573 # include some extra logic to handle that better.
15371574 if not isinstance (gt , np .ndarray ):
1538- raise TypeError (
1539- f"Expected gt to be a numpy.ndarray, " f"got { type (gt ).__name__ } "
1540- )
1575+ raise TypeError (f"Expected gt to be a numpy.ndarray, got { type (gt ).__name__ } " )
15411576 if not isinstance (mapping , np .ndarray ):
15421577 raise TypeError (
1543- f"Expected mapping to be a numpy.ndarray, " f" got { type (mapping ).__name__ } "
1578+ f"Expected mapping to be a numpy.ndarray, got { type (mapping ).__name__ } "
15441579 )
15451580 assert gt .ndim == 3
15461581 assert mapping .ndim == 3
@@ -1562,11 +1597,11 @@ def _genotype_array_map_alleles(gt, mapping):
15621597def _dask_genotype_array_map_alleles (gt , mapping ):
15631598 if not isinstance (gt , da .Array ):
15641599 raise TypeError (
1565- f"Expected gt to be a dask.array.Array, " f" got { type (gt ).__name__ } "
1600+ f"Expected gt to be a dask.array.Array, got { type (gt ).__name__ } "
15661601 )
15671602 if not isinstance (mapping , np .ndarray ):
15681603 raise TypeError (
1569- f"Expected mapping to be a numpy.ndarray, " f" got { type (mapping ).__name__ } "
1604+ f"Expected mapping to be a numpy.ndarray, got { type (mapping ).__name__ } "
15701605 )
15711606 assert gt .ndim == 3
15721607 assert mapping .ndim == 2
0 commit comments