Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/scanpy/external/exporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,8 @@ def cellbrowser( # noqa: PLR0913
"""
try:
import cellbrowser.cellbrowser as cb
except ImportError:
logg.error(
"The package cellbrowser is not installed. "
"Install with 'pip install cellbrowser' and retry."
)
except ImportError as e:
e.add_note("Please install `cellbrowser` and try again.")
raise

data_dir = str(data_dir)
Expand Down
4 changes: 2 additions & 2 deletions src/scanpy/external/pp/_bbknn.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ def bbknn( # noqa: PLR0913
try:
from bbknn import bbknn
except ImportError as e:
msg = "Please install bbknn: `pip install bbknn`."
raise ImportError(msg) from e
e.add_note("Please install `bbknn` and try again.")
raise
return bbknn(
adata=adata,
batch_key=batch_key,
Expand Down
4 changes: 2 additions & 2 deletions src/scanpy/external/pp/_dca.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def dca( # noqa: PLR0913
try:
from dca.api import dca
except ImportError as e:
msg = "Please install dca package (>= 0.2.1) via `pip install dca`"
raise ImportError(msg) from e
e.add_note("Please install `dca` (≥ 0.2.1) and try again.")
raise e

return dca(
adata,
Expand Down
4 changes: 2 additions & 2 deletions src/scanpy/external/pp/_harmony_integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def harmony_integrate(
try:
import harmonypy
except ImportError as e:
msg = "\nplease install harmonypy:\n\n\tpip install harmonypy"
raise ImportError(msg) from e
e.add_note("Please install `harmonypy` and try again.")
raise

x = adata.obsm[basis].astype(np.float64)

Expand Down
4 changes: 2 additions & 2 deletions src/scanpy/external/pp/_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def magic( # noqa: PLR0913
try:
from magic import MAGIC
except ImportError as e:
msg = "Please install magic package via `pip install magic-impute`"
raise ImportError(msg) from e
e.add_note("Please install `magic-impute` and try again.")
raise
else:
if pkg_version("magic-impute") < Version(MIN_VERSION):
msg = (
Expand Down
4 changes: 2 additions & 2 deletions src/scanpy/external/pp/_mnn_correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ def mnn_correct( # noqa: PLR0913
import mnnpy
from mnnpy import mnn_correct
except ImportError as e:
msg = "Please install the package mnnpy (https://github.com/chriscainx/mnnpy). "
raise ImportError(msg) from e
e.add_note("Please install `mnnpy` and try again.")
raise

n_jobs = settings.n_jobs if n_jobs is None else n_jobs

Expand Down
4 changes: 2 additions & 2 deletions src/scanpy/external/pp/_scanorama_integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def scanorama_integrate(
try:
import scanorama
except ImportError as e:
msg = "\nplease install Scanorama:\n\n\tpip install scanorama"
raise ImportError(msg) from e
e.add_note("Please install `scanorama` and try again.")
raise

# Get batch indices in linear time.
curr_batch = None
Expand Down
4 changes: 2 additions & 2 deletions src/scanpy/external/tl/_harmony_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def harmony_timeseries(
try:
import harmony
except ImportError as e:
msg = "\nplease install harmony:\n\n\tpip install harmonyTS"
raise ImportError(msg) from e
e.add_note("Please install `harmonyTS` and try again.")
raise

adata = adata.copy() if copy else adata
logg.info("Harmony augmented affinity matrix")
Expand Down
6 changes: 3 additions & 3 deletions src/scanpy/external/tl/_palantir.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ def palantir_results(
return pr_res


def _check_import():
def _check_import() -> None:
try:
import palantir # noqa: F401
except ImportError as e:
msg = "\nplease install palantir:\n\tpip install palantir"
raise ImportError(msg) from e
e.add_note("Please install `palantir` and try again.")
raise
7 changes: 2 additions & 5 deletions src/scanpy/external/tl/_phate.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,8 @@ def phate( # noqa: PLR0913
try:
import phate
except ImportError as e:
msg = (
"You need to install the package `phate`: please run `pip install "
"--user phate` in a terminal."
)
raise ImportError(msg) from e
e.add_note("Please install `phate` and try again.")
raise
x_phate = phate.PHATE(
n_components=n_components,
k=k,
Expand Down
9 changes: 2 additions & 7 deletions src/scanpy/external/tl/_sam.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,8 @@ def sam( # noqa: PLR0913
try:
from samalg import SAM
except ImportError as e:
msg = (
"\nplease install sam-algorithm: \n\n"
"\tgit clone git://github.com/atarashansky/self-assembling-manifold.git\n"
"\tcd self-assembling-manifold\n"
"\tpip install ."
)
raise ImportError(msg) from e
e.add_note("Please install `sc-sam` and try again.")
raise

logg.info("Self-assembling manifold")

Expand Down
4 changes: 2 additions & 2 deletions src/scanpy/external/tl/_trimap.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def trimap( # noqa: PLR0913
try:
from trimap import TRIMAP
except ImportError as e:
msg = "\nplease install trimap: \n\n\tsudo pip install trimap"
raise ImportError(msg) from e
e.add_note("Please install `trimap` and try again.")
raise
adata = adata.copy() if copy else adata
start = logg.info("computing TriMap")
adata = adata.copy() if copy else adata
Expand Down
4 changes: 2 additions & 2 deletions src/scanpy/external/tl/_wishbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def wishbone(
try:
from wishbone.core import wishbone as c_wishbone
except ImportError as e:
msg = "\nplease install wishbone:\n\n\thttps://github.com/dpeerlab/wishbone"
raise ImportError(msg) from e
e.add_note("Please install `wishbone` and try again.")
raise

# Start cell index
s = np.where(adata.obs_names == start_cell)[0]
Expand Down
7 changes: 5 additions & 2 deletions src/scanpy/metrics/_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,11 @@ def modularity_array(
try:
import igraph as ig
except ImportError as e: # pragma: no cover
msg = "igraph is require for computing modularity"
raise ImportError(msg) from e
e.add_note(
"`igraph` is required for computing modularity. "
"Please install `igraph` and try again."
)
raise
igraph_mode: str = ig.ADJ_DIRECTED if is_directed else ig.ADJ_UNDIRECTED
graph: ig.Graph = ig.Graph.Weighted_Adjacency(connectivities, mode=igraph_mode)
return graph.modularity(_codes(labels))
Expand Down
10 changes: 5 additions & 5 deletions src/scanpy/plotting/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,12 +1132,12 @@ def _create_white_to_color_gradient(
popt = np.get_printoptions()
try:
import colour
except ImportError:
msg = (
"Please install the `colour-science` package to use `group_colors`: "
"`pip install colour-science` or `pip install scanpy[plotting]`"
except ImportError as e:
e.add_note(
"`colour-science` is required for using `group_colors`. "
"Please install `scanpy[plotting]` (or `colour-science` directly) and try again."
)
raise ImportError(msg) from None
raise
finally: # https://github.com/colour-science/colour/issues/1388
np.set_printoptions(legacy=popt["legacy"])

Expand Down
4 changes: 2 additions & 2 deletions src/scanpy/preprocessing/_highly_variable_genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ def _highly_variable_genes_seurat_v3( # noqa: PLR0912, PLR0915
try:
from skmisc.loess import loess
except ImportError as e:
msg = "Please install skmisc package via `pip install --user scikit-misc"
raise ImportError(msg) from e
e.add_note("Please install `scikit-misc` and try again.")
raise
df = pd.DataFrame(index=adata.var_names)
data = _get_obs_rep(adata, layer=layer)
raise_if_dask_feature_axis_chunked(data)
Expand Down
5 changes: 4 additions & 1 deletion src/scanpy/preprocessing/_scrublet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ def scrublet( # noqa: PLR0913
if threshold is None and not find_spec("skimage"): # pragma: no cover
# Scrublet.call_doublets requires `skimage` with `threshold=None` but PCA
# is called early, which is wasteful if there is not `skimage`
msg = "threshold is None and thus scrublet requires skimage, but skimage is not installed."
msg = (
"`threshold` is None and thus scrublet requires `scikit-image`. "
"Please install `scanpy[scrublet]` (or `scikit-image` directly) and try again."
)
raise ValueError(msg)

if copy:
Expand Down
8 changes: 4 additions & 4 deletions src/scanpy/queries/_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def simple_query(
try:
from pybiomart import Server
except ImportError as e:
msg = "This method requires the `pybiomart` module to be installed."
raise ImportError(msg) from e
e.add_note("Please install `pybiomart` and try again.")
raise
server = Server(host, use_cache=use_cache)
dataset = server.marts["ENSEMBL_MART_ENSEMBL"].datasets[f"{org}_gene_ensembl"]
res = dataset.query(attributes=attrs, filters=filters, use_attr_names=True)
Expand Down Expand Up @@ -278,8 +278,8 @@ def enrich(
try:
from gprofiler import GProfiler
except ImportError as e:
msg = "This method requires the `gprofiler-official` module to be installed."
raise ImportError(msg) from e
e.add_note("Please install `gprofiler-official` and try again.")
raise
gprofiler = GProfiler(user_agent="scanpy", return_dataframe=True)
gprofiler_kwargs = dict(gprofiler_kwargs)
for k in ["organism"]:
Expand Down
6 changes: 4 additions & 2 deletions src/scanpy/tools/_leiden.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,10 @@ def _validate_flavor(
try:
import leidenalg # noqa: F401
except ImportError as e:
msg = "Please install the leiden algorithm: `conda install -c conda-forge leidenalg` or `pip install leidenalg`."
raise ImportError(msg) from e
e.add_note(
"Please install `scanpy[leiden]` (or `leidenalg` directly) and try again."
)
raise
flavor = "leidenalg"
case _:
msg = f"flavor must be either 'igraph' or 'leidenalg', but {flavor!r} was passed"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ def test_dotplot_group_colors_raises_error_on_missing_dep(
markers = ["CD79A"]
group_colors = {"CD19+ B": "blue"}

with pytest.raises(ImportError, match="pip install colour-science"):
with pytest.raises(ImportError, match=r"colour-science.*required"):
sc.pl.dotplot(
adata,
markers,
Expand Down
Loading