From 940feb5d10ce7fdf3b46773f1f712eae5c97f5c3 Mon Sep 17 00:00:00 2001 From: Connor Tann <71127464+connortann@users.noreply.github.com> Date: Thu, 7 Mar 2024 13:58:01 +0000 Subject: [PATCH] More comprehensive scipy fix Signed-off-by: Connor Tann <71127464+connortann@users.noreply.github.com> --- slicer/slicer_internal.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/slicer/slicer_internal.py b/slicer/slicer_internal.py index 98d7478..2d10d28 100644 --- a/slicer/slicer_internal.py +++ b/slicer/slicer_internal.py @@ -567,8 +567,6 @@ class UnifiedDataHandler: ("numpy", "ndarray"): ArrayHandler, ("scipy.sparse.csc", "csc_matrix"): ArrayHandler, ("scipy.sparse.csr", "csr_matrix"): ArrayHandler, - ("scipy.sparse._csc", "csc_matrix"): ArrayHandler, - ("scipy.sparse._csr", "csr_matrix"): ArrayHandler, ("scipy.sparse.dok", "dok_matrix"): ArrayHandler, ("scipy.sparse.lil", "lil_matrix"): ArrayHandler, ("pandas.core.frame", "DataFrame"): DataFrameHandler, @@ -607,7 +605,7 @@ def default_alias(cls, o): def _type_name(o: object) -> Tuple[str, str]: - return o.__class__.__module__, o.__class__.__name__ + return _handle_module_aliases(o.__class__.__module__), o.__class__.__name__ def _safe_isinstance( @@ -618,3 +616,16 @@ def _safe_isinstance( return o_module == module_name and o_type == type_name else: return o_module == module_name and o_type in type_name + + +def _handle_module_aliases(module_name): + # scipy module such as "scipy.sparse.csc" were renamed to "scipy.sparse._csc". + # Standardise by removing underscores for compatibility with future versions + # Else just pass module name unchanged + module_map = { + "scipy.sparse._csc": "scipy.sparse.csc", + "scipy.sparse._csr": "scipy.sparse.csr", + "scipy.sparse._dok": "scipy.sparse.dok", + "scipy.sparse._lil": "scipy.sparse.lil", + } + return module_map.get(module_name, module_name)