Skip to content

Commit a28f5e4

Browse files
Backport PR scverse#2048: (chore): Re-introduce strict warnings (scverse#2055)
Co-authored-by: Philipp A <flying-sheep@web.de>
1 parent 29f394f commit a28f5e4

7 files changed

Lines changed: 38 additions & 12 deletions

File tree

.github/workflows/test-cpu.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
ENVS_JSON=$(NO_COLOR=1 uvx hatch env show --json | jq -c 'to_entries
3939
| map(
4040
select(.key | startswith("hatch-test"))
41-
| { name: .key, python: .value.python }
41+
| { name: .key, python: .value.python, args: (.value."extra-args" // [] | join(" ")) }
4242
)')
4343
echo "envs=${ENVS_JSON}" | tee $GITHUB_OUTPUT
4444
test:
@@ -71,7 +71,7 @@ jobs:
7171
run: uvx hatch -v env create ${{ matrix.env.name }}
7272

7373
- name: Run tests
74-
run: uvx hatch run ${{ matrix.env.name }}:run-cov -v --color=yes -n auto --cov --cov-report=xml --junitxml=test-data/test-results.xml -m "${{matrix.io_mark}}"
74+
run: uvx hatch run ${{ matrix.env.name }}:run-cov -v --color=yes -n auto --cov --cov-report=xml --junitxml=test-data/test-results.xml -m "${{ matrix.io_mark }}" ${{ matrix.env.args }}
7575

7676
- name: Upload coverage data
7777
uses: codecov/codecov-action@v5

hatch.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ overrides.matrix.deps.python = [
3636
overrides.matrix.deps.features = [
3737
{ if = [ "stable", "pre" ], value = "test" },
3838
]
39+
overrides.matrix.deps.extra-args = { if = [ "stable", "pre" ], value = [ "--strict-warnings" ] }
3940

4041
[[envs.hatch-test.matrix]]
4142
deps = [ "stable", "pre", "min" ]

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ addopts = [
146146
filterwarnings = [
147147
"ignore::anndata._warnings.OldFormatWarning",
148148
"ignore::anndata._warnings.ExperimentalFeatureWarning",
149+
"ignore:.*first_column_names:FutureWarning:scanpy", # scanpy 1.10.x
149150
]
150151
# When `--strict-warnings` is used, all warnings are treated as errors, except those:
151152
filterwarnings_when_strict = [
@@ -158,6 +159,8 @@ filterwarnings_when_strict = [
158159
"default:The codec `vlen-utf8:UserWarning",
159160
"default:The dtype `StringDType():UserWarning",
160161
"default:Consolidated metadata is:UserWarning",
162+
"default:.*Structured:zarr.core.dtype.common.UnstableSpecificationWarning",
163+
"default:.*FixedLengthUTF32:zarr.core.dtype.common.UnstableSpecificationWarning",
161164
]
162165
python_files = "test_*.py"
163166
testpaths = [

src/anndata/_io/read.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ def read_csv(
4848
dtype
4949
Numpy data type.
5050
"""
51-
return read_text(filename, delimiter, first_column_names, dtype)
51+
return read_text(
52+
filename, delimiter, first_column_names=first_column_names, dtype=dtype
53+
)
5254

5355

5456
def read_excel(
@@ -360,18 +362,26 @@ def read_text(
360362
Numpy data type.
361363
"""
362364
if not isinstance(filename, PathLike | str | bytes):
363-
return _read_text(filename, delimiter, first_column_names, dtype)
365+
return _read_text(
366+
filename, delimiter, first_column_names=first_column_names, dtype=dtype
367+
)
364368

365369
filename = Path(filename)
366370
if filename.suffix == ".gz":
367371
with gzip.open(str(filename), mode="rt") as f:
368-
return _read_text(f, delimiter, first_column_names, dtype)
372+
return _read_text(
373+
f, delimiter, first_column_names=first_column_names, dtype=dtype
374+
)
369375
elif filename.suffix == ".bz2":
370376
with bz2.open(str(filename), mode="rt") as f:
371-
return _read_text(f, delimiter, first_column_names, dtype)
377+
return _read_text(
378+
f, delimiter, first_column_names=first_column_names, dtype=dtype
379+
)
372380
else:
373381
with filename.open() as f:
374-
return _read_text(f, delimiter, first_column_names, dtype)
382+
return _read_text(
383+
f, delimiter, first_column_names=first_column_names, dtype=dtype
384+
)
375385

376386

377387
def _iter_lines(file_like: Iterable[str]) -> Generator[str, None, None]:
@@ -385,7 +395,8 @@ def _iter_lines(file_like: Iterable[str]) -> Generator[str, None, None]:
385395
def _read_text( # noqa: PLR0912, PLR0915
386396
f: Iterator[str],
387397
delimiter: str | None,
388-
first_column_names: bool | None, # noqa: FBT001
398+
*,
399+
first_column_names: bool | None,
389400
dtype: str,
390401
) -> AnnData:
391402
comments = []

src/anndata/_io/specs/methods.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,11 @@ def write_recarray_zarr(
695695
from anndata.compat import _to_fixed_length_strings
696696

697697
elem = _to_fixed_length_strings(elem)
698-
if isinstance(f, H5Group) or is_zarr_v2():
698+
if is_zarr_v2():
699699
f.create_dataset(k, data=elem, shape=elem.shape, **dataset_kwargs)
700700
else:
701701
dataset_kwargs = dataset_kwargs.copy()
702702
dataset_kwargs = zarr_v3_compressor_compat(dataset_kwargs)
703-
# TODO: zarr’s on-disk format v3 doesn’t support this dtype
704703
f.create_array(k, shape=elem.shape, dtype=elem.dtype, **dataset_kwargs)
705704
f[k][...] = elem
706705

tests/test_readwrite.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,10 @@ def test_scanpy_krumsiek11(tmp_path, diskfmt, roundtrip):
844844
import scanpy as sc
845845

846846
# TODO: this should be fixed in scanpy instead
847-
with pytest.warns(UserWarning, match=r"Observation names are not unique"):
847+
with pytest.warns(UserWarning, match=r"Observation names are not unique"): # noqa: PT031
848+
warnings.filterwarnings(
849+
"ignore", r".*first_column_names.*no longer positional", FutureWarning
850+
)
848851
orig = sc.datasets.krumsiek11()
849852
del orig.uns["highlights"] # Can’t write int keys
850853
# Can’t write "string" dtype: https://github.com/scverse/anndata/issues/679

tests/test_structured_arrays.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from __future__ import annotations
22

3+
import warnings
34
from itertools import combinations, product
45
from typing import TYPE_CHECKING
56

67
import numpy as np
78

89
import anndata as ad
910
from anndata import AnnData
11+
from anndata.compat import is_zarr_v2
1012
from anndata.tests.helpers import gen_vstr_recarray
1113

1214
if TYPE_CHECKING:
@@ -27,7 +29,14 @@ def assert_str_contents_equal(A, B):
2729

2830
def test_io(
2931
tmp_path, diskfmt: Literal["zarr", "h5ad"], diskfmt2: Literal["zarr", "h5ad"]
30-
):
32+
) -> None:
33+
if not is_zarr_v2():
34+
from zarr.core.dtype.common import UnstableSpecificationWarning
35+
36+
warnings.filterwarnings( # raised by “S10” dtype in the recarray below
37+
"default", r".*NullTerminatedBytes", UnstableSpecificationWarning
38+
)
39+
3140
read1 = lambda pth: getattr(ad, f"read_{diskfmt}")(pth)
3241
write1 = lambda adata, pth: getattr(adata, f"write_{diskfmt}")(pth)
3342
read2 = lambda pth: getattr(ad, f"read_{diskfmt2}")(pth)

0 commit comments

Comments
 (0)