Skip to content

Commit dde809d

Browse files
(chore): export read_elem and write_elem from the main package (#1598)
Co-authored-by: Philipp A. <flying-sheep@web.de>
1 parent a92bda8 commit dde809d

19 files changed

Lines changed: 127 additions & 79 deletions

benchmarks/benchmarks/sparse_dataset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from scipy import sparse
66

77
from anndata import AnnData
8-
from anndata.experimental import sparse_dataset, write_elem
8+
from anndata._io.specs import write_elem
9+
from anndata.experimental import sparse_dataset
910

1011

1112
def make_alternating_mask(n):

docs/api.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ Reading other file formats.
5252
5353
```
5454

55+
Reading individual portions (`obs`, `varm` etc.) of the `AnnData` object.
56+
57+
```{eval-rst}
58+
.. autosummary::
59+
:toctree: generated/
60+
61+
read_elem
62+
63+
```
64+
5565
## Writing
5666

5767
Writing to anndata’s native file format `.h5ad`.
@@ -74,6 +84,16 @@ Writing to other formats.
7484
AnnData.write_zarr
7585
```
7686

87+
Writing individual portions (`obs`, `varm` etc.) of the `AnnData` object.
88+
89+
```{eval-rst}
90+
.. autosummary::
91+
:toctree: generated/
92+
93+
write_elem
94+
95+
```
96+
7797
(experimental-api)=
7898

7999
## Experimental API
@@ -100,8 +120,6 @@ Interface for accessing on-disk sparse data:
100120
:toctree: generated/
101121
102122
experimental.sparse_dataset
103-
experimental.CSRDataset
104-
experimental.CSCDataset
105123
```
106124

107125
Out of core concatenation
@@ -119,8 +137,6 @@ Low level methods for reading and writing elements of an `AnnData` object to a s
119137
.. autosummary::
120138
:toctree: generated/
121139
122-
experimental.read_elem
123-
experimental.write_elem
124140
experimental.read_elem_as_dask
125141
```
126142

@@ -141,8 +157,6 @@ Types used by the former:
141157
:toctree: generated/
142158
143159
experimental.IOSpec
144-
experimental.InMemoryElem
145-
experimental.RWAble
146160
experimental.Read
147161
experimental.Write
148162
experimental.ReadCallback
@@ -168,3 +182,15 @@ Types used by the former:
168182
settings
169183
settings.override
170184
```
185+
186+
## Custom Types/Classes for Readable/Writeable Elements
187+
188+
```{eval-rst}
189+
.. autosummary::
190+
:toctree: generated/
191+
192+
CSRDataset
193+
CSCDataset
194+
RWAble
195+
InMemoryElem
196+
```

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ def setup(app: Sphinx):
142142
"anndata._types.WriteCallback": "anndata.experimental.WriteCallback",
143143
"anndata._types.Read": "anndata.experimental.Read",
144144
"anndata._types.Write": "anndata.experimental.Write",
145-
"anndata._types.RWAble": "anndata.experimental.RWAble",
145+
"anndata._types.RWAble": "anndata.RWAble",
146146
}
147147
autodoc_type_aliases = dict(
148148
NDArray=":data:`~numpy.typing.NDArray`",
149-
RWAble=":data:`~anndata.experimental.RWAble`",
149+
RWAble=":data:`~anndata.RWAble`",
150150
**{
151-
f"{v}variantInMemoryType": ":data:`~anndata.experimental.InMemoryElem`"
151+
f"{v}variantInMemoryType": ":data:`~anndata.InMemoryElem`"
152152
for v in ["In", "Co", "Contra"]
153153
},
154154
)

docs/fileformat-prose.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ That is, we store an indicator array (or mask) of null values alongside the arra
476476
:sync: hdf5
477477
478478
```python
479-
>>> from anndata.experimental import write_elem
479+
>>> from anndata import write_elem
480480
>>> null_store = h5py.File("tmp.h5", mode="w")
481481
>>> int_array = pd.array([1, None, 3, 4])
482482
>>> int_array
@@ -498,7 +498,7 @@ nullable_integer/values <HDF5 dataset "values": shape (4,), type "<i8">
498498
:sync: zarr
499499
500500
```python
501-
>>> from anndata.experimental import write_elem
501+
>>> from anndata import write_elem
502502
>>> null_store = zarr.open()
503503
>>> int_array = pd.array([1, None, 3, 4])
504504
>>> int_array
@@ -635,7 +635,7 @@ function:
635635

636636
```python
637637
>>> import awkward as ak
638-
>>> from anndata.experimental import read_elem
638+
>>> from anndata import read_elem
639639
>>> awkward_group = store["varm/transcript"]
640640
>>> ak.from_buffers(
641641
... awkward_group.attrs["form"],

docs/release-notes/0.10.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
* Concatenate on-disk anndata objects with {func}`anndata.experimental.concat_on_disk` {pr}`955` {user}`selmanozleyen`
1515
* AnnData can now hold dask arrays with `scipy.sparse.spmatrix` chunks {pr}`1114` {user}`ivirshup`
16-
* Public API for interacting with on disk sparse arrays: {func}`~anndata.experimental.sparse_dataset`, {class}`~anndata.experimental.CSRDataset`, and {class}`~anndata.experimental.CSCDataset` {pr}`765` {user}`ilan-gold` {user}`ivirshup`
16+
* Public API for interacting with on disk sparse arrays: {func}`~anndata.experimental.sparse_dataset`, {class}`~anndata.CSRDataset`, and {class}`~anndata.CSCDataset` {pr}`765` {user}`ilan-gold` {user}`ivirshup`
1717
* Improved performance for simple slices of OOC sparse arrays {pr}`1131` {user}`ivirshup`
1818

1919
**Improved errors and warnings**

docs/release-notes/0.10.2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#### Bug fixes
55

66
* Added compatibility layer for packages relying on `anndata._core.sparse_dataset.SparseDataset`.
7-
Note that this API is *deprecated* and new code should use {class}`~anndata.experimental.CSRDataset`, {class}`~anndata.experimental.CSCDataset`, and {func}`~anndata.experimental.sparse_dataset` instead.
7+
Note that this API is *deprecated* and new code should use {class}`~anndata.CSRDataset`, {class}`~anndata.CSCDataset`, and {func}`~anndata.experimental.sparse_dataset` instead.
88
{pr}`1185` {user}`ivirshup`
99
* Handle deprecation warning from `pd.Categorical.map` thrown during `anndata.concat` {pr}`1189` {user}`flying-sheep` {user}`ivirshup`
1010
* Fixed extra steps being included in IO tracebacks {pr}`1193` {user}`flying-sheep`

docs/release-notes/0.8.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This should make it much easier to support new datatypes, use partial access, an
1515

1616
- Each element should be tagged with an `encoding_type` and `encoding_version`. See updated docs on the {doc}`file format </fileformat-prose>`
1717
- Support for nullable integer and boolean data arrays. More data types to come!
18-
- Experimental support for low level access to the IO API via {func}`~anndata.experimental.read_elem` and {func}`~anndata.experimental.write_elem`
18+
- Experimental support for low level access to the IO API via {func}`~anndata.read_elem` and {func}`~anndata.write_elem`
1919

2020
#### Features
2121

docs/release-notes/1598.feature.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Export {func}`~anndata.write_elem` and {func}`~anndata.read_elem` directly from the main package instead of `experimental` {user}`ilan-gold`

docs/release-notes/1616.doc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Correct {attr}`anndata.AnnData.X` type to include {class}`~anndata.experimental.CSRDataset` and {class}`~anndata.experimental.CSCDataset` as possible types {user}`ilan-gold`
1+
Correct {attr}`anndata.AnnData.X` type to include {class}`~anndata.CSRDataset` and {class}`~anndata.CSCDataset` as possible types and being deprecation process for non-csr/csc {class}`scipy.sparse.spmatrix` types in {attr}`anndata.AnnData.X` {user}`ilan-gold`

src/anndata/__init__.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from ._core.anndata import AnnData
2525
from ._core.merge import concat
2626
from ._core.raw import Raw
27+
from ._core.sparse_dataset import CSCDataset, CSRDataset
2728
from ._io import (
2829
read_csv,
2930
read_excel,
@@ -35,19 +36,27 @@
3536
read_umi_tools,
3637
read_zarr,
3738
)
39+
from ._io.specs import read_elem, write_elem
3840
from ._settings import settings
41+
from ._types import InMemoryElem
42+
from ._types import RWAble as _RWAble
3943
from ._warnings import (
4044
ExperimentalFeatureWarning,
4145
ImplicitModificationWarning,
4246
OldFormatWarning,
4347
WriteWarning,
4448
)
4549

50+
# Sphinx can’t find data docstrings when objects are re-exported
51+
RWAble = _RWAble
52+
"""A serializable object, excluding :class:`anndata.AnnData` objects i.e., something that can be stored in `uns` or `obsm`."""
53+
54+
4655
# Experimental needs to be imported last
47-
from . import experimental # isort: skip
56+
from . import experimental # noqa: E402 isort: skip
4857

4958
# We use these in tests by attribute access
50-
from . import _io, logging # noqa: F401 isort: skip
59+
from . import _io, logging # noqa: F401, E402 isort: skip
5160

5261

5362
def read(*args, **kwargs):
@@ -75,6 +84,12 @@ def read(*args, **kwargs):
7584
"read_text",
7685
"read_mtx",
7786
"read_zarr",
87+
"read_elem",
88+
"write_elem",
89+
"InMemoryElem",
90+
"RWAble",
91+
"CSRDataset",
92+
"CSCDataset",
7893
"OldFormatWarning",
7994
"WriteWarning",
8095
"ImplicitModificationWarning",

0 commit comments

Comments
 (0)