Skip to content

Commit e06e875

Browse files
committed
make random state argument handling more consistent
- always default to non-None random_state (consistent within muon and with scanpy) - fix condition before setting random state in .tl.leiden (closes #154)
1 parent 55ef22c commit e06e875

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

muon/_atac/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ def tss_enrichment(
900900
extend_downstream: int = 1000,
901901
n_tss: int = 2000,
902902
return_tss: bool = True,
903-
random_state=None,
903+
random_state: int | None = 0,
904904
barcodes: Optional[str] = None,
905905
):
906906
"""

muon/_core/tools.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ def _cluster(
930930
data: Union[MuData, AnnData],
931931
resolution: Optional[Union[float, Sequence[float], Mapping[str, float]]] = None,
932932
mod_weights: Optional[Union[Sequence[float], Mapping[str, float]]] = None,
933-
random_state: int = 0,
933+
random_state: int | None = 0,
934934
key_added: str = "louvain",
935935
neighbors_key: str = None,
936936
directed: bool = True,
@@ -1003,7 +1003,7 @@ def _cluster(
10031003
partition_type = alg.RBConfigurationVertexPartition
10041004

10051005
optimiser = alg.Optimiser()
1006-
if random_state:
1006+
if random_state is not None:
10071007
optimiser.set_rng_seed(random_state)
10081008

10091009
# The same as leiden.find_partition_multiplex() (louvain.find_partition_multiplex())
@@ -1059,7 +1059,7 @@ def leiden(
10591059
data: Union[MuData, AnnData],
10601060
resolution: Optional[Union[float, Sequence[float], Mapping[str, float]]] = None,
10611061
mod_weights: Optional[Union[Sequence[float], Mapping[str, float]]] = None,
1062-
random_state: int = 0,
1062+
random_state: int | None = 0,
10631063
key_added: str = "leiden",
10641064
neighbors_key: str = None,
10651065
directed: bool = True,
@@ -1135,7 +1135,7 @@ def louvain(
11351135
data: Union[MuData, AnnData],
11361136
resolution: Optional[Union[float, Sequence[float], Mapping[str, float]]] = None,
11371137
mod_weights: Optional[Union[Sequence[float], Mapping[str, float]]] = None,
1138-
random_state: int = 0,
1138+
random_state: int | None = 0,
11391139
key_added: str = "louvain",
11401140
neighbors_key: str = None,
11411141
directed: bool = True,
@@ -1368,7 +1368,7 @@ def ica(
13681368
basis="X_pca",
13691369
n_components=None,
13701370
*,
1371-
random_state=None,
1371+
random_state: int | None = 0,
13721372
scale=False,
13731373
copy=False,
13741374
**kwargs,

muon/_prot/preproc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def dsb(
2222
empty_counts_range: Optional[Tuple[Real, Real]] = None,
2323
cell_counts_range: Optional[Tuple[Real, Real]] = None,
2424
add_layer: bool = False,
25-
random_state: Optional[Union[int, np.random.RandomState, None]] = None,
25+
random_state: Optional[Union[int, np.random.RandomState, None]] = 0,
2626
) -> Union[None, MuData]:
2727
"""
2828
Normalize protein expression with DSB (Denoised and Scaled by Background)

0 commit comments

Comments
 (0)