99import importlib .util
1010import inspect
1111import re
12- import sys
1312import warnings
1413from contextlib import suppress
1514from enum import Enum
6463 _ForT = TypeVar ("_ForT" , bound = Callable | type )
6564
6665
66+ __all__ = [
67+ "AssoResult" ,
68+ "Empty" ,
69+ "NeighborsView" ,
70+ "_choose_graph" ,
71+ "_doc_params" ,
72+ "_empty" ,
73+ "_resolve_axis" ,
74+ "annotate_doc_types" ,
75+ "axis_mul_or_truediv" ,
76+ "axis_nnz" ,
77+ "check_array_function_arguments" ,
78+ "check_nonnegative_integers" ,
79+ "check_presence_download" ,
80+ "check_use_raw" ,
81+ "compute_association_matrix_of_groups" ,
82+ "descend_classes_and_funcs" ,
83+ "ensure_igraph" ,
84+ "get_literal_vals" ,
85+ "indent" ,
86+ "is_backed_type" ,
87+ "is_backed_type" ,
88+ "raise_not_implemented_error_if_backed_type" ,
89+ "renamed_arg" ,
90+ "sanitize_anndata" ,
91+ "select_groups" ,
92+ "update_params" ,
93+ "warn_once" ,
94+ ]
95+
96+
6797LegacyUnionType = type (Union [int , str ]) # noqa: UP007
6898
6999
@@ -88,7 +118,7 @@ def ensure_igraph() -> None:
88118 raise ImportError (msg )
89119
90120
91- def getdoc (c_or_f : Callable | type ) -> str | None :
121+ def _getdoc (c_or_f : Callable | type ) -> str | None :
92122 if getattr (c_or_f , "__doc__" , None ) is None :
93123 return None
94124 doc = inspect .getdoc (c_or_f )
@@ -142,7 +172,7 @@ def wrapper(*args, **kwargs):
142172 return decorator
143173
144174
145- def _import_name (full_name : str ) -> Any :
175+ def import_name (full_name : str ) -> Any :
146176 from importlib import import_module
147177
148178 parts = full_name .split ("." )
@@ -197,7 +227,7 @@ def descend_classes_and_funcs(mod: ModuleType, root: str, encountered=None):
197227def annotate_doc_types (mod : ModuleType , root : str ):
198228 for c_or_f in descend_classes_and_funcs (mod , root ):
199229 with suppress (AttributeError ):
200- c_or_f .getdoc = partial (getdoc , c_or_f )
230+ c_or_f .getdoc = partial (_getdoc , c_or_f )
201231
202232
203233_leading_whitespace_re = re .compile ("(^[ ]*)(?:[^ \n ])" , re .MULTILINE )
@@ -227,7 +257,7 @@ def dec(obj: _ForT) -> _ForT:
227257 return dec
228258
229259
230- def _check_array_function_arguments (** kwargs ):
260+ def check_array_function_arguments (** kwargs ):
231261 """Check for invalid arguments when an array is passed.
232262
233263 Helper for functions that work on either AnnData objects or array-likes.
@@ -239,7 +269,7 @@ def _check_array_function_arguments(**kwargs):
239269 raise TypeError (msg )
240270
241271
242- def _check_use_raw (
272+ def check_use_raw (
243273 adata : AnnData ,
244274 use_raw : None | bool , # noqa: FBT001
245275 * ,
@@ -540,14 +570,14 @@ def get_literal_vals(typ: UnionType | Any) -> KeysView[Any]:
540570 Scaling_T = TypeVar ("Scaling_T" , DaskArray , np .ndarray )
541571
542572
543- def broadcast_axis (divisor : Scaling_T , axis : Literal [0 , 1 ]) -> Scaling_T :
573+ def _broadcast_axis (divisor : Scaling_T , axis : Literal [0 , 1 ]) -> Scaling_T :
544574 divisor = np .ravel (divisor )
545575 if axis :
546576 return divisor [None , :]
547577 return divisor [:, None ]
548578
549579
550- def check_op (op ):
580+ def _check_op (op ) -> None :
551581 if op not in {truediv , mul }:
552582 msg = f"{ op } not one of truediv or mul"
553583 raise ValueError (msg )
@@ -564,8 +594,8 @@ def axis_mul_or_truediv(
564594 allow_divide_by_zero : bool = True ,
565595 out : ArrayLike | None = None ,
566596) -> np .ndarray :
567- check_op (op )
568- scaling_array = broadcast_axis (scaling_array , axis )
597+ _check_op (op )
598+ scaling_array = _broadcast_axis (scaling_array , axis )
569599 if op is mul :
570600 return np .multiply (x , scaling_array , out = out )
571601 if not allow_divide_by_zero :
@@ -584,7 +614,7 @@ def _(
584614 allow_divide_by_zero : bool = True ,
585615 out : CSBase | None = None ,
586616) -> CSBase :
587- check_op (op )
617+ _check_op (op )
588618 if out is not None and x .data is not out .data :
589619 msg = "`out` argument provided but not equal to X. This behavior is not supported for sparse matrix scaling."
590620 raise ValueError (msg )
@@ -621,7 +651,7 @@ def new_data_op(x):
621651 ).T
622652
623653
624- def make_axis_chunks (
654+ def _make_axis_chunks (
625655 x : DaskArray , axis : Literal [0 , 1 ]
626656) -> tuple [tuple [int ], tuple [int ]]:
627657 if axis == 0 :
@@ -640,14 +670,14 @@ def _(
640670 allow_divide_by_zero : bool = True ,
641671 out : None = None ,
642672) -> DaskArray :
643- check_op (op )
673+ _check_op (op )
644674 if out is not None :
645675 msg = "`out` is not `None`. Do not do in-place modifications on dask arrays."
646676 raise TypeError (msg )
647677
648678 import dask .array as da
649679
650- scaling_array = broadcast_axis (scaling_array , axis )
680+ scaling_array = _broadcast_axis (scaling_array , axis )
651681 row_scale = axis == 0
652682 column_scale = axis == 1
653683
@@ -668,11 +698,11 @@ def _(
668698 warnings .warn (
669699 "Rechunking scaling_array in user operation" , UserWarning , stacklevel = 3
670700 )
671- scaling_array = scaling_array .rechunk (make_axis_chunks (x , axis ))
701+ scaling_array = scaling_array .rechunk (_make_axis_chunks (x , axis ))
672702 else :
673703 scaling_array = da .from_array (
674704 scaling_array ,
675- chunks = make_axis_chunks (x , axis ),
705+ chunks = _make_axis_chunks (x , axis ),
676706 )
677707 return da .map_blocks (
678708 axis_mul_or_truediv ,
@@ -802,27 +832,6 @@ def select_groups(
802832 return groups_order_subset , groups_masks_obs
803833
804834
805- def warn_with_traceback ( # noqa: PLR0917
806- message , category , filename , lineno , file = None , line = None
807- ) -> None :
808- """Get full tracebacks when warning is raised by setting.
809-
810- warnings.showwarning = warn_with_traceback
811-
812- See Also
813- --------
814- https://stackoverflow.com/questions/22373927/get-traceback-of-warnings
815-
816- """
817- import traceback
818-
819- traceback .print_stack ()
820- log = ( # noqa: F841 # TODO Does this need fixing?
821- file if hasattr (file , "write" ) else sys .stderr
822- )
823- settings .write (warnings .formatwarning (message , category , filename , lineno , line ))
824-
825-
826835def warn_once (msg : str , category : type [Warning ], stacklevel : int = 0 ) -> None :
827836 warnings .warn (msg , category , stacklevel = stacklevel + 1 )
828837 # You'd think `'once'` works, but it doesn't at the repl and in notebooks
@@ -837,19 +846,6 @@ def check_presence_download(filename: Path, backup_url):
837846 _download (backup_url , filename )
838847
839848
840- def lazy_import (full_name ):
841- """Import a module in a way that it’s only executed on member access."""
842- try :
843- return sys .modules [full_name ]
844- except KeyError :
845- spec = importlib .util .find_spec (full_name )
846- module = importlib .util .module_from_spec (spec )
847- loader = importlib .util .LazyLoader (spec .loader )
848- # Make module with proper locking and get it inserted into sys.modules.
849- loader .exec_module (module )
850- return module
851-
852-
853849# --------------------------------------------------------------------------------
854850# Neighbors
855851# --------------------------------------------------------------------------------
0 commit comments