Skip to content

Commit

Permalink
More comprehensive scipy fix
Browse files Browse the repository at this point in the history
Signed-off-by: Connor Tann <[email protected]>
  • Loading branch information
connortann committed Mar 7, 2024
1 parent 99e69e9 commit 940feb5
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions slicer/slicer_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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)

0 comments on commit 940feb5

Please sign in to comment.