Skip to content

Commit

Permalink
Merge branch 'main' into ig/fix_set_index
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep authored Aug 12, 2024
2 parents c823476 + daed86f commit 7f874ba
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 112 deletions.
5 changes: 3 additions & 2 deletions benchmarks/benchmarks/readwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ def track_read_full_memratio(self, *_):
def peakmem_read_backed(self, *_):
anndata.read_h5ad(self.filepath, backed="r")

def mem_read_backed_object(self, *_):
return anndata.read_h5ad(self.filepath, backed="r")
# causes benchmarking to break from: https://github.com/pympler/pympler/issues/151
# def mem_read_backed_object(self, *_):
# return anndata.read_h5ad(self.filepath, backed="r")


class H5ADWriteSuite:
Expand Down
41 changes: 3 additions & 38 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime
from functools import partial
from importlib import metadata
from pathlib import Path
from pathlib import Path, PurePosixPath
from typing import TYPE_CHECKING

from docutils import nodes
Expand Down Expand Up @@ -60,6 +60,7 @@
"sphinx.ext.linkcode",
"nbsphinx",
"IPython.sphinxext.ipython_console_highlighting",
"patch_sphinx_toolbox_autoprotocol",
"sphinx_toolbox.more_autodoc.autoprotocol",
]
myst_enable_extensions = [
Expand All @@ -71,6 +72,7 @@
autosummary_generate = True
autodoc_member_order = "bysource"
issues_github_path = "scverse/anndata"
rtd_links_prefix = PurePosixPath("src")
# autodoc_default_flags = ['members']
napoleon_google_docstring = False
napoleon_numpy_docstring = True
Expand Down Expand Up @@ -190,40 +192,3 @@ def setup(app: Sphinx):
"Miscellaneous",
)
]


def patch_sphinx_toolbox_autoprotocol():
"""Compat hack: https://github.com/sphinx-toolbox/sphinx-toolbox/issues/168"""

from sphinx.ext.autodoc import ObjectMember
from sphinx_toolbox.more_autodoc.autoprotocol import ProtocolDocumenter

if TYPE_CHECKING:
from typing import Self

class ObjectMemberCompat(ObjectMember):
@classmethod
def from_other(cls, other: ObjectMember) -> Self:
return cls(
other.__name__,
other.object,
docstring=other.docstring,
class_=other.class_,
skipped=other.skipped,
)

def __iter__(self):
return iter([self.__name__, self.object])

filter_orig = ProtocolDocumenter.filter_members

def filter_members(
self, members: list[ObjectMember], want_all: bool
) -> list[tuple[str, object, bool]]:
member_tuples = [ObjectMemberCompat.from_other(m) for m in members]
return filter_orig(self, member_tuples, want_all)

ProtocolDocumenter.filter_members = filter_members


patch_sphinx_toolbox_autoprotocol()
43 changes: 43 additions & 0 deletions docs/extensions/patch_sphinx_toolbox_autoprotocol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from sphinx.ext.autodoc import ObjectMember
from sphinx_toolbox.more_autodoc.autoprotocol import ProtocolDocumenter

if TYPE_CHECKING:
from typing import Self

from sphinx.application import Sphinx


def patch_sphinx_toolbox_autoprotocol():
"""Compat hack: https://github.com/sphinx-toolbox/sphinx-toolbox/issues/168"""

class ObjectMemberCompat(ObjectMember):
@classmethod
def from_other(cls, other: ObjectMember) -> Self:
return cls(
other.__name__,
other.object,
docstring=other.docstring,
class_=other.class_,
skipped=other.skipped,
)

def __iter__(self):
return iter([self.__name__, self.object])

filter_orig = ProtocolDocumenter.filter_members

def filter_members(
self, members: list[ObjectMember], want_all: bool
) -> list[tuple[str, object, bool]]:
member_tuples = [ObjectMemberCompat.from_other(m) for m in members]
return filter_orig(self, member_tuples, want_all)

ProtocolDocumenter.filter_members = filter_members


def setup(_app: Sphinx) -> None:
patch_sphinx_toolbox_autoprotocol()
4 changes: 2 additions & 2 deletions docs/release-notes/0.10.9.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Add warning for setting `X` on a view with repeated indices {pr}`1501` {user}`ilan-gold`
* Coerce {class}`numpy.matrix` classes to arrays when trying to store them in `AnnData` {pr}`1516` {user}`flying-sheep`
* Fix for setting a dense `X` view with a sparse matrix {pr}`1532` {user}`ilan-gold`
* Upper bound {mod}`numpy` for `gpu` installation on account of https://github.com/cupy/cupy/issues/8391 {pr}`1540` {user}`ilan-gold`
* Upper bound {mod}`numpy` for `gpu` installation on account of {issue}`cupy/cupy#8391` {pr}`1540` {user}`ilan-gold`
* Fix writing large number of columns for `h5` files {pr}`1147` {user}`ilan-gold` {user}`selmanozleyen`
* Upper bound dask on account of https://github.com/scverse/anndata/issues/1579 {pr}`1580` {user}`ilan-gold`
* Upper bound dask on account of {issue}`1579` {pr}`1580` {user}`ilan-gold`
* Ensure setting {attr}`pandas.DataFrame.index` on a view of a {class}`~anndata.AnnData` instantiates the {class}`~pandas.DataFrame` from the view {pr}`1586` {user}`ilan-gold`

#### Documentation
Expand Down
5 changes: 3 additions & 2 deletions docs/release-notes/0.11.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

* Allow `axis` parameter of e.g. :func:`anndata.concat` to accept `'obs'` and `'var` {pr}`1244` {user}`flying-sheep`
* Add `settings` object with methods for altering internally-used options, like checking for uniqueness on `obs`' index {pr}`1270` {user}`ilan-gold`
* Add `should_remove_unused_categories` option to `anndata.settings` to override current behavior. Default is `True` (i.e., previous behavior). Please refer to the [documentation](https://anndata.readthedocs.io/en/latest/generated/anndata.settings.html) for usage. {pr}`1340` {user}`ilan-gold`
* `scipy.sparse.csr_array` and `scipy.sparse.csc_array` are now supported when constructing `AnnData` objects {pr}`1028` {user}`ilan-gold` {user}`isaac-virshup`
* Add `should_check_uniqueness` option to `anndata.settings` to override current behavior. Default is `True` (i.e., previous behavior). Please refer to the [documentation](https://anndata.readthedocs.io/en/latest/generated/anndata.settings.html) for usage. {pr}`1507` {user}`ilan-gold`
* Add {attr}`~anndata.settings.should_remove_unused_categories` option to {attr}`anndata.settings` to override current behavior {pr}`1340` {user}`ilan-gold`
* Add {attr}`~anndata.settings.should_check_uniqueness` option to {attr}`anndata.settings` to override current behavior {pr}`1507` {user}`ilan-gold`
* Add :func:`~anndata.experimental.read_elem_as_dask` function to handle i/o with sparse and dense arrays {pr}`1469` {user}`ilan-gold`
* Add functionality to write from GPU {class}`dask.array.Array` to disk {pr}`1550` {user}`ilan-gold`
* Add ability to convert strings to categoricals on write in {meth}`~anndata.AnnData.write_h5ad` and {meth}`~anndata.AnnData.write_zarr` via `convert_strings_to_categoricals` parameter {pr}`1474` {user}` falexwolf`

#### Bugfix

Expand Down
4 changes: 2 additions & 2 deletions src/anndata/_io/h5ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def write_h5ad(
adata: AnnData,
*,
as_dense: Sequence[str] = (),
strings_to_categoricals: bool = True,
convert_strings_to_categoricals: bool = True,
dataset_kwargs: Mapping[str, Any] = MappingProxyType({}),
**kwargs,
) -> None:
Expand All @@ -63,7 +63,7 @@ def write_h5ad(
if "raw/X" in as_dense and adata.raw is None:
raise ValueError("Cannot specify writing `raw/X` to dense if it doesn’t exist.")

if strings_to_categoricals:
if convert_strings_to_categoricals:
adata.strings_to_categoricals()
if adata.raw is not None:
adata.strings_to_categoricals(adata.raw.var)
Expand Down
4 changes: 2 additions & 2 deletions src/anndata/_io/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def write_zarr(
adata: AnnData,
*,
chunks: tuple[int, ...] | None = None,
strings_to_categoricals: bool = True,
convert_strings_to_categoricals: bool = True,
**ds_kwargs,
) -> None:
if isinstance(store, Path):
store = str(store)
if strings_to_categoricals:
if convert_strings_to_categoricals:
adata.strings_to_categoricals()
if adata.raw is not None:
adata.strings_to_categoricals(adata.raw.var)
Expand Down
Loading

0 comments on commit 7f874ba

Please sign in to comment.