Skip to content

Commit 555f546

Browse files
authored
Prep 0.8 (#689)
* Fix pr ref * draft * Typo fix * note removal of xlrd dep * Remove datetime addition from release notes * Add read_elem, write_elem to release (breaks build) Added `read_elem`, `write_elem` to experimental and release notes. Breaks build due to typing in docs. * Make docs build * A little cleanup around X=None * Bump required version of h5py (tentative change) * pandas 1.4.0 compat (only test suite was broken, probably don't need release) * Note release candidate is out
1 parent 0020a1a commit 555f546

File tree

11 files changed

+55
-20
lines changed

11 files changed

+55
-20
lines changed

anndata/_core/anndata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def _gen_dataframe(anno, length, index_names):
116116

117117
@_gen_dataframe.register(pd.DataFrame)
118118
def _(anno, length, index_names):
119-
anno = anno.copy()
119+
anno = anno.copy(deep=False)
120120
if not is_string_dtype(anno.index):
121121
warnings.warn("Transforming to str index.", ImplicitModificationWarning)
122122
anno.index = anno.index.astype(str)

anndata/_io/h5ad.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
from .specs import read_elem, write_elem
3131
from anndata._warnings import OldFormatWarning
3232

33-
H5Group = Union[h5py.Group, h5py.File]
34-
H5Dataset = h5py.Dataset
3533
T = TypeVar("T")
3634

3735

anndata/_io/specs/registry.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from collections.abc import Mapping
44
from functools import singledispatch, wraps
5-
from typing import NamedTuple, Tuple, Type, Callable, Union
5+
from typing import Any, NamedTuple, Tuple, Type, Callable, Union
66

77

8-
from anndata.compat import _read_attr
8+
from anndata.compat import _read_attr, ZarrArray, ZarrGroup, H5Group, H5Array
99
from anndata._io.utils import report_write_key_on_error, report_read_key_on_error
1010

1111
# TODO: This probably should be replaced by a hashable Mapping due to conversion b/w "_" and "-"
@@ -137,15 +137,15 @@ def get_spec(
137137

138138
@report_write_key_on_error
139139
def write_elem(
140-
f: "Union[h5py.Group, zarr.Group]",
140+
f: "Union[H5Group, ZarrGroup]",
141141
k: str,
142-
elem,
142+
elem: Any,
143143
*args,
144144
modifiers=frozenset(),
145145
**kwargs,
146146
):
147147
"""
148-
Write an element to a disk store.
148+
Write an element to a disk store using it's anndata encoding.
149149
150150
Params
151151
------
@@ -175,7 +175,10 @@ def write_elem(
175175
_REGISTRY.get_writer(dest_type, t, modifiers)(f, k, elem, *args, **kwargs)
176176

177177

178-
def read_elem(elem, modifiers: frozenset(str) = frozenset()):
178+
def read_elem(
179+
elem: Union[H5Array, H5Group, ZarrGroup, ZarrArray],
180+
modifiers: frozenset(str) = frozenset(),
181+
) -> Any:
179182
"""Read an element from an on disk store."""
180183
return _REGISTRY.get_reader(type(elem), get_spec(elem), frozenset(modifiers))(elem)
181184

anndata/compat/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class Empty:
1818
pass
1919

2020

21+
H5Group = Union[h5py.Group, h5py.File]
22+
H5Array = h5py.Dataset
23+
24+
2125
# try importing zarr, dask, and zappy
2226
from packaging import version
2327

anndata/experimental/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
from .multi_files import AnnCollection
22
from .pytorch import AnnLoader
3+
4+
from anndata._io.specs import read_elem, write_elem

anndata/tests/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def slice_subset(index, min_size=2):
222222

223223

224224
def single_subset(index):
225-
return index[np.random.randint(0, len(index), size=())]
225+
return index[np.random.randint(0, len(index))]
226226

227227

228228
@pytest.fixture(

anndata/tests/test_readwrite.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ def test_read_umi_tools():
525525
def test_write_categorical(tmp_path, diskfmt):
526526
adata_pth = tmp_path / f"adata.{diskfmt}"
527527
orig = ad.AnnData(
528-
X=np.ones((5, 5)),
529528
obs=pd.DataFrame(
530529
dict(
531530
cat1=["a", "a", "b", np.nan, np.nan],
@@ -542,7 +541,6 @@ def test_write_categorical(tmp_path, diskfmt):
542541
def test_write_categorical_index(tmp_path, diskfmt):
543542
adata_pth = tmp_path / f"adata.{diskfmt}"
544543
orig = ad.AnnData(
545-
X=np.ones((5, 5)),
546544
uns={"df": pd.DataFrame(index=pd.Categorical(list("aabcd")))},
547545
)
548546
getattr(orig, f"write_{diskfmt}")(adata_pth)
@@ -557,7 +555,9 @@ def test_write_categorical_index(tmp_path, diskfmt):
557555
def test_dataframe_reserved_columns(tmp_path, diskfmt):
558556
reserved = ("_index",)
559557
adata_pth = tmp_path / f"adata.{diskfmt}"
560-
orig = ad.AnnData(X=np.ones((5, 5)))
558+
orig = ad.AnnData(
559+
obs=pd.DataFrame(index=np.arange(5)), var=pd.DataFrame(index=np.arange(5))
560+
)
561561
for colname in reserved:
562562
to_write = orig.copy()
563563
to_write.obs[colname] = np.ones(5)
@@ -608,7 +608,6 @@ def test_write_string_types(tmp_path, diskfmt):
608608
adata_pth = tmp_path / f"adata.{diskfmt}"
609609

610610
adata = ad.AnnData(
611-
np.ones((3, 3)),
612611
obs=pd.DataFrame(
613612
np.ones((3, 2)),
614613
columns=["a", np.str_("b")],

docs/api.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ Two classes for working with batched access to collections of many `AnnData` obj
8080
experimental.AnnCollection
8181
experimental.AnnLoader
8282

83+
Low level methods for reading and writing elements of an `AnnData`` object to a store:
84+
85+
86+
.. autosummary::
87+
:toctree: generated/
88+
89+
experimental.read_elem
90+
experimental.write_elem
91+
8392

8493
Errors and warnings
8594
-------------------

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def setup(app: Sphinx):
8787
xarray=("http://xarray.pydata.org/en/stable/", None),
8888
)
8989
qualname_overrides = {
90+
"h5py._hl.group.Group": "h5py.Group",
91+
"h5py._hl.files.File": "h5py.File",
9092
"anndata._core.anndata.AnnData": "anndata.AnnData",
9193
# Temporarily
9294
"anndata._core.raw.Raw": "anndata.AnnData",

docs/release-latest.rst

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,38 @@
22
.. role:: smaller
33

44

5-
On `master` :small:`the future`
6-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5+
`0.8.0` :small:`the future`
6+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
77

8-
.. rubric:: Bug fixes
8+
.. note:: 0.8.0 is currently in the release candidate phase. Install this version with `pip install "anndata==0.8.0rc1"`.
9+
10+
.. rubric:: IO Specification
11+
12+
Internal handling of IO has been overhauled.
13+
This should make it much easier to support new datatypes, use partial access, and use `AnnData` internally in other formats.
14+
15+
- Each element should be tagged with an `encoding_type` and `encoding_version`. See updated docs on the :doc:`file format <fileformat-prose>`
16+
- Support for nullable integer and boolean data arrays. More data types to come!
17+
- Experimental support for low level access to the IO API via :func:`~anndata.experimental.read_elem` and :func:`~anndata.experimental.write_elem`
918

1019
.. rubric:: Features
1120

1221
- Compatibility with `h5ad` files written from Julia :pr:`569` :smaller:`I Kats`
1322
- Many logging messages that should have been warnings are now warnings :pr:`650` :smaller:`I Virshup`
1423
- Significantly more efficient :func:`anndata.read_umi_tools` :pr:`661` :smaller:`I Virshup`
1524
- Fixed deepcopy of a copy of a view retaining sparse matrix view mixin type :pr:`670` :smaller:`M Klein`
16-
- In many cases :attr:`~anndata.AnnData.X` can now be `None` :pr:`463` :smaller:`R Cannoodt` :pr:`667` :smaller:`I Virshup`. Remaining work is documented in :issue:`467`.
25+
- In many cases :attr:`~anndata.AnnData.X` can now be `None` :pr:`463` :smaller:`R Cannoodt` :pr:`677` :smaller:`I Virshup`. Remaining work is documented in :issue:`467`.
26+
- Removed hard `xlrd` dependency :smaller:`I Virshup`
27+
- `obs` and `var` dataframes are no longer copied by default on `AnnData` instantiation :issue:`371` :smaller:`I Virshup`
28+
29+
.. rubric:: Bug fixes
30+
31+
- Fixed issue where `.copy` was creating sparse matrices views when copying :pr:`670` :smaller:`michalk8`
32+
33+
.. rubric:: Dependencies
1734

18-
.. rubric:: Documentation
35+
* `xlrd` dropped as a hard dependency
36+
* Now requires `h5py` `v3.0.0` or newer
1937

2038

2139
0.7.8 :small:`9 November, 2021`

0 commit comments

Comments
 (0)