Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c7dad8f
WIP catch all warnings
flying-sheep Jul 21, 2025
422cae9
fix some warnings
flying-sheep Jul 21, 2025
bca40a8
test_get works
flying-sheep Jul 21, 2025
02ecd49
hvg works
flying-sheep Jul 21, 2025
218075e
ingest
flying-sheep Jul 21, 2025
6fc449e
logging
flying-sheep Jul 21, 2025
e909c27
neighbors
flying-sheep Jul 21, 2025
73767d5
normalize and todense
flying-sheep Jul 21, 2025
9ca80b8
plotting
flying-sheep Jul 21, 2025
429d017
preprocessing
flying-sheep Jul 21, 2025
0d9341d
qc
flying-sheep Jul 21, 2025
05a259b
rank_genes_groups
flying-sheep Jul 21, 2025
ff44d3d
scaling
flying-sheep Jul 21, 2025
ab396ee
score_genes
flying-sheep Jul 21, 2025
127f42b
sim
flying-sheep Jul 21, 2025
42c4e68
visium_sge
flying-sheep Jul 21, 2025
504d484
refactor preprocessing
flying-sheep Jul 22, 2025
0393f71
confusion matrix
flying-sheep Jul 22, 2025
6cd59d8
doctests
flying-sheep Jul 22, 2025
ab686b5
rest
flying-sheep Jul 22, 2025
d3991f3
relnote
flying-sheep Jul 22, 2025
66c6810
maybe fix file closing
flying-sheep Jul 22, 2025
50db520
Fix doctest env
flying-sheep Jul 22, 2025
4d3580f
follow advice
flying-sheep Jul 22, 2025
ef938f8
fix rest
flying-sheep Jul 22, 2025
5ed7ecb
try fixing leidenalg
flying-sheep Jul 22, 2025
111a3d6
hopefully this works
flying-sheep Jul 22, 2025
be03a09
excel
flying-sheep Jul 22, 2025
b8806c3
nx
flying-sheep Jul 23, 2025
5d494a9
tSNE
flying-sheep Jul 23, 2025
14533e3
h5py
flying-sheep Jul 23, 2025
fd15637
add version
flying-sheep Jul 23, 2025
3944394
pandas
flying-sheep Jul 23, 2025
91bbdef
broader capture
flying-sheep Jul 23, 2025
2c7aef2
maybe actually the last ones!
flying-sheep Jul 23, 2025
e4334fe
speculative fix
flying-sheep Jul 23, 2025
d55eaf0
more speculative fixing yay
flying-sheep Jul 23, 2025
4b6ec91
i really hope that’s it
flying-sheep Jul 23, 2025
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:

env:
PYTEST_ADDOPTS: "-v --color=yes -n auto --internet-tests --junitxml=test-data/test-results.xml"
PYTHONTRACEMALLOC: "20"
FORCE_COLOR: "1"
MPLBACKEND: agg
UV_CONSTRAINT: ci/constraints.txt
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ After installing installing e.g. [Miniconda][], run:
$ conda install -c conda-forge scanpy python-igraph leidenalg
```

Pull Scanpy [from PyPI][] (consider using `pip3` to access Python 3):
Pull Scanpy [from PyPI][]:

```console
$ pip install scanpy
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/3724.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Raise fewer redundant warnings, mainly in {mod}`scanpy.pl` and {mod}`scanpy.datasets` functions {smaller}`P Angerer`
29 changes: 9 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,15 @@ markers = [
"anndata_dask_support: tests that require dask support in anndata",
]
filterwarnings = [
# legacy-api-wrap: internal use of positional API
"error:The specified parameters:FutureWarning",
# When calling `.show()` in tests, this is raised
"ignore:FigureCanvasAgg is non-interactive:UserWarning",

# We explicitly handle the below errors in tests
"error:`anndata.read` is deprecated:FutureWarning",
"error:Observation names are not unique:UserWarning",
"error:The dtype argument is deprecated and will be removed:FutureWarning",
"error:The behavior of DataFrame\\.sum with axis=None is deprecated:FutureWarning",
"error:The default of observed=False is deprecated:FutureWarning",
"error:Series\\.__getitem__ treating keys as positions is deprecated:FutureWarning",
"error:The default value of 'ignore' for the `na_action` parameter in pandas\\.Categorical\\.map:FutureWarning",
"error:The provided callable.* is currently using:FutureWarning",
"error:The behavior of DataFrame concatenation with empty or all-NA entries is deprecated:FutureWarning",
"error:A value is trying to be set on a copy of a slice from a DataFrame",
"error:No data for colormapping provided via 'c'",
"error:\\n*The `scale` parameter has been renamed and will be removed",
"error:\\n*Passing `palette` without assigning `hue` is deprecated",
"error:\\n*Setting a gradient palette using color= is deprecated",
"error",
# Umap warns when tensorflow isn’t installed.
"ignore::ImportWarning:umap",
# seaborn causes some matplotlib warnings
"ignore::PendingDeprecationWarning:seaborn",
# matplotlib<3.10.4 causes a Pillow warning
"ignore:.*Pillow:DeprecationWarning",
# we want to see and eventually fix these
"default::numba.core.errors.NumbaPerformanceWarning",
Comment thread
flying-sheep marked this conversation as resolved.
Outdated
]

[tool.coverage.run]
Expand Down
7 changes: 4 additions & 3 deletions src/scanpy/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def ensure_igraph() -> None:
msg = (
"Please install the igraph package: "
"`conda install -c conda-forge python-igraph` or "
"`pip3 install igraph`."
"`pip install igraph`."
)
raise ImportError(msg)

Expand Down Expand Up @@ -127,6 +127,7 @@ def renamed_arg(old_name, new_name, *, pos_0: bool = False):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
__tracebackhide__ = True
if old_name in kwargs:
f_name = func.__name__
pos_str = (
Expand Down Expand Up @@ -832,8 +833,8 @@ def warn_with_traceback( # noqa: PLR0917
settings.write(warnings.formatwarning(message, category, filename, lineno, line))


def warn_once(msg: str, category: type[Warning], stacklevel: int = 1):
warnings.warn(msg, category, stacklevel=stacklevel)
def warn_once(msg: str, category: type[Warning], stacklevel: int = 0) -> None:
warnings.warn(msg, category, stacklevel=stacklevel + 1)
# You'd think `'once'` works, but it doesn't at the repl and in notebooks
warnings.filterwarnings("ignore", category=category, message=re.escape(msg))

Expand Down
23 changes: 16 additions & 7 deletions src/scanpy/datasets/_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

import numpy as np
import pandas as pd
from anndata import AnnData
from anndata import AnnData, OldFormatWarning

from .. import _utils
from .._compat import deprecated, old_positionals
from .._settings import settings
from .._utils._doctests import doctest_internet, doctest_needs
from ..readwrite import read, read_visium
from ._utils import check_datasetdir_exists, filter_oldformatwarning
from ._utils import check_datasetdir_exists

if TYPE_CHECKING:
from typing import Literal
Expand Down Expand Up @@ -123,6 +123,8 @@ def burczynski06() -> AnnData:
--------
>>> import scanpy as sc
>>> sc.datasets.burczynski06()
UserWarning: Variable names are not unique. To make them unique, call `.var_names_make_unique`.
utils.warn_names_duplicates("var")
Comment thread
ilan-gold marked this conversation as resolved.
AnnData object with n_obs × n_vars = 127 × 22283
obs: 'groups'

Expand Down Expand Up @@ -318,7 +320,6 @@ def toggleswitch() -> AnnData:
return adata


@filter_oldformatwarning
def pbmc68k_reduced() -> AnnData:
r"""Subsampled and processed 68k PBMCs.

Expand Down Expand Up @@ -354,12 +355,12 @@ def pbmc68k_reduced() -> AnnData:
"""
filename = HERE / "10x_pbmc68k_reduced.h5ad"
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=OldFormatWarning, module="anndata")
warnings.filterwarnings("ignore", category=FutureWarning, module="anndata")
return read(filename)


@doctest_internet
@filter_oldformatwarning
@check_datasetdir_exists
def pbmc3k() -> AnnData:
r"""3k PBMCs from 10x Genomics.
Expand Down Expand Up @@ -406,12 +407,13 @@ def pbmc3k() -> AnnData:

"""
url = "https://falexwolf.de/data/pbmc3k_raw.h5ad"
adata = read(settings.datasetdir / "pbmc3k_raw.h5ad", backup_url=url)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=OldFormatWarning, module="anndata")
adata = read(settings.datasetdir / "pbmc3k_raw.h5ad", backup_url=url)
return adata


@doctest_internet
@filter_oldformatwarning
@check_datasetdir_exists
def pbmc3k_processed() -> AnnData:
"""Processed 3k PBMCs from 10x Genomics.
Expand Down Expand Up @@ -447,6 +449,7 @@ def pbmc3k_processed() -> AnnData:
url = "https://raw.githubusercontent.com/chanzuckerberg/cellxgene/main/example-dataset/pbmc3k.h5ad"

with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=OldFormatWarning, module="anndata")
warnings.filterwarnings("ignore", category=FutureWarning, module="anndata")
return read(settings.datasetdir / "pbmc3k_processed.h5ad", backup_url=url)

Expand Down Expand Up @@ -540,6 +543,10 @@ def visium_sge(
--------
>>> import scanpy as sc
>>> sc.datasets.visium_sge(sample_id="V1_Breast_Cancer_Block_A_Section_1")
FutureWarning: Use `squidpy.datasets.visium` instead.
sc.datasets.visium_sge(sample_id="V1_Breast_Cancer_Block_A_Section_1")
UserWarning: Variable names are not unique. To make them unique, call `.var_names_make_unique`.
utils.warn_names_duplicates("var")
AnnData object with n_obs × n_vars = 3798 × 36601
obs: 'in_tissue', 'array_row', 'array_col'
var: 'gene_ids', 'feature_types', 'genome'
Expand All @@ -552,4 +559,6 @@ def visium_sge(
sample_id, spaceranger_version, download_image=include_hires_tiff
)
source_image_path = sample_dir / "image.tif" if include_hires_tiff else None
return read_visium(sample_dir, source_image_path=source_image_path)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", r".*squidpy\.read", FutureWarning)
return read_visium(sample_dir, source_image_path=source_image_path)
19 changes: 0 additions & 19 deletions src/scanpy/datasets/_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from __future__ import annotations

import warnings
from functools import wraps
from typing import TYPE_CHECKING

import anndata as ad
from packaging.version import Version

from .._settings import settings

if TYPE_CHECKING:
Expand All @@ -24,18 +20,3 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
return f(*args, **kwargs)

return wrapper


def filter_oldformatwarning(f: Callable[P, R]) -> Callable[P, R]:
"""Filter anndata.OldFormatWarning from being thrown by the wrapped function."""

@wraps(f)
def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
with warnings.catch_warnings():
if Version(ad.__version__).release >= (0, 8):
warnings.filterwarnings(
"ignore", category=ad.OldFormatWarning, module="anndata"
)
return f(*args, **kwargs)

return wrapper
5 changes: 3 additions & 2 deletions src/scanpy/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ def _set_log_file(settings: SettingsMeta) -> None:
file = settings.logfile
name = settings.logpath
root = settings._root_logger
for handler in list(root.handlers):
root.removeHandler(handler)
handler.close()
h = logging.StreamHandler(file) if name is None else logging.FileHandler(name)
h.setFormatter(_LogFormatter())
h.setLevel(root.level)
for handler in list(root.handlers):
root.removeHandler(handler)
root.addHandler(h)


Expand Down
2 changes: 1 addition & 1 deletion src/scanpy/plotting/_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ def rank_genes_groups_violin( # noqa: PLR0913
_ax.set_title(f"{group_name} vs. {reference}")
_ax.legend_.remove()
_ax.set_ylabel("expression")
_ax.set_xticklabels(new_gene_names, rotation="vertical")
_ax.set_xticks(range(len(new_gene_names)), new_gene_names, rotation="vertical")
writekey = (
f"rank_genes_groups_{adata.uns[key]['params']['groupby']}_{group_name}"
)
Expand Down
4 changes: 2 additions & 2 deletions src/scanpy/plotting/_tools/paga.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ def moving_average(a):
),
)
if show_yticks:
groups_axis.set_yticklabels(["", xlabel, ""], fontsize=ytick_fontsize)
groups_axis.set_yticks(range(3), [xlabel, "", ""], fontsize=ytick_fontsize)
else:
groups_axis.set_yticks([])
groups_axis.set_frame_on(False)
Expand Down Expand Up @@ -1331,7 +1331,7 @@ def moving_average(a):
cmap=color_map_anno,
)
if show_yticks:
anno_axis.set_yticklabels(["", anno, ""], fontsize=ytick_fontsize)
anno_axis.set_yticks(range(3), [anno, "", ""], fontsize=ytick_fontsize)
Comment thread
flying-sheep marked this conversation as resolved.
anno_axis.tick_params(axis="both", which="both", length=0)
else:
anno_axis.set_yticks([])
Expand Down
11 changes: 11 additions & 0 deletions src/scanpy/plotting/_tools/scatterplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Normalize,
)
from matplotlib.figure import Figure # noqa: TC002
from matplotlib.markers import MarkerStyle
from numpy.typing import NDArray # noqa: TC002
from packaging.version import Version

Expand All @@ -36,6 +37,7 @@
_empty,
sanitize_anndata,
)
from ..._utils._doctests import doctest_internet
from ...get import _check_mask
from ...tools._draw_graph import _Layout # noqa: TC001
from .. import _utils
Expand Down Expand Up @@ -404,12 +406,16 @@ def embedding( # noqa: PLR0912, PLR0913, PLR0915
**kwargs_outline,
)

edgecolor = kwargs_scatter.pop("edgecolor", None)
if not MarkerStyle(marker[count]).is_filled():
edgecolor = None
cax = scatter(
coords[:, 0],
coords[:, 1],
c=color_vector,
rasterized=settings._vector_friendly,
marker=marker[count],
edgecolor=edgecolor,
**kwargs_scatter,
)

Expand Down Expand Up @@ -923,6 +929,7 @@ def pca(


@deprecated("Use `squidpy.pl.spatial_scatter` instead.")
@doctest_internet
@_wraps_plot_scatter
@_doc_params(
adata_color_etc=doc_adata_color_etc,
Expand Down Expand Up @@ -993,8 +1000,12 @@ def spatial( # noqa: PLR0913

>>> import scanpy as sc
>>> adata = sc.datasets.visium_sge("Targeted_Visium_Human_Glioblastoma_Pan_Cancer")
FutureWarning: Use `squidpy.datasets.visium` instead.
adata = sc.datasets.visium_sge("Targeted_Visium_Human_Glioblastoma_Pan_Cancer")
>>> sc.pp.calculate_qc_metrics(adata, inplace=True)
>>> sc.pl.spatial(adata, color="log1p_n_genes_by_counts")
FutureWarning: Use `squidpy.pl.spatial_scatter` instead.
sc.pl.spatial(adata, color="log1p_n_genes_by_counts")

See Also
--------
Expand Down
5 changes: 4 additions & 1 deletion src/scanpy/preprocessing/_highly_variable_genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,10 @@ def _subset_genes(
def _nth_highest(x: NDArray[np.float64] | DaskArray, n: int) -> float | DaskArray:
x = x[~np.isnan(x)]
if n > x.size:
msg = "`n_top_genes` > number of normalized dispersions, returning all genes with normalized dispersions."
msg = (
f"`n_top_genes` (={n}) > number of normalized dispersions (={x.size}), "
"returning all genes with normalized dispersions."
)
# 5: caller -> 4: `highly_variable_genes` -> 3: `_…_single_batch` -> 2: `_subset_genes` -> 1: here
warnings.warn(msg, UserWarning, stacklevel=5)
n = x.size
Expand Down
14 changes: 0 additions & 14 deletions src/scanpy/preprocessing/_pca/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import TYPE_CHECKING, Literal, overload
from warnings import warn

import anndata as ad
import numpy as np
from anndata import AnnData
from packaging.version import Version
Expand Down Expand Up @@ -240,19 +239,6 @@ def pca( # noqa: PLR0912, PLR0913, PLR0915
if is_backed_type(X) and layer is not None:
msg = f"PCA is not implemented for matrices of type {type(X)} from layers"
raise NotImplementedError(msg)
# See: https://github.com/scverse/scanpy/pull/2816#issuecomment-1932650529
if (
Version(ad.__version__) < Version("0.9")
and mask_var is not None
and isinstance(X, np.ndarray)
):
warnings.warn(
"When using a mask parameter with anndata<0.9 on a dense array, the PCA"
"can have slightly different results due the array being column major "
"instead of row major.",
UserWarning,
stacklevel=2,
)

# check_random_state returns a numpy RandomState when passed an int but
# dask needs an int for random state
Expand Down
Loading
Loading