From 5ebee34e39e82393dcb9fe6e98f7dc3172431b41 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Fri, 1 Nov 2024 09:41:41 -0400 Subject: [PATCH 1/3] docstr tweaks, typo fix --- python-spec/src/somacore/base.py | 15 ++++++++------- python-spec/src/somacore/experiment.py | 2 +- python-spec/src/somacore/query/query.py | 1 - 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/python-spec/src/somacore/base.py b/python-spec/src/somacore/base.py index 187664ca..8d6198f4 100644 --- a/python-spec/src/somacore/base.py +++ b/python-spec/src/somacore/base.py @@ -113,13 +113,14 @@ def closed(self) -> bool: raise NotImplementedError() soma_type: ClassVar[LiteralString] - """A string describing the SOMA type of this object. This is constant.""" - # This uses ClassVar since you can't do abstract class properties. - # This is the equivalent, just without abc-based automatic verification. - # - # Overrides are marked Final with an ignore[misc] because mypy by default - # wants this to be mutable, and doesn't like overriding the mutable member - # with a Final member. + """A string describing the SOMA type of this object. This is constant. + + This uses ClassVar since you can't do abstract class properties. + This is the equivalent, just without abc-based automatic verification. + Overrides are marked Final with an ignore[misc] because mypy by default + wants this to be mutable, and doesn't like overriding the mutable member + with a Final member. + """ # Context management diff --git a/python-spec/src/somacore/experiment.py b/python-spec/src/somacore/experiment.py index b570aa2a..fbdcb517 100644 --- a/python-spec/src/somacore/experiment.py +++ b/python-spec/src/somacore/experiment.py @@ -15,7 +15,7 @@ _MeasColl = TypeVar("_MeasColl", bound=collection.Collection[measurement.Measurement]) """An implementation of a collection of Measurements.""" _SceneColl = TypeVar("_SceneColl", bound=collection.Collection[scene.Scene]) -"""An implemenation of a collection of spatial data.""" +"""An implementation of a collection of spatial data.""" _RootSO = TypeVar("_RootSO", bound=base.SOMAObject) """The root SOMA object type of the implementation.""" diff --git a/python-spec/src/somacore/query/query.py b/python-spec/src/somacore/query/query.py index af60b935..bbfb4624 100644 --- a/python-spec/src/somacore/query/query.py +++ b/python-spec/src/somacore/query/query.py @@ -414,7 +414,6 @@ def _read( ) -> "_AxisQueryResult": """Reads the entire query result in memory. - This is a low-level routine intended to be used by loaders for other in-core formats, such as AnnData, which can be created from the resulting objects. From 480d5007de10a376c0ebb6fd882103b90f1ad5d1 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Fri, 1 Nov 2024 09:49:59 -0400 Subject: [PATCH 2/3] Enable `ruff` auto-fixing --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 82a93840..b3f31e2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,7 @@ tag_regex = '^python-(?P[vV]?\d+(?:\.\d+){0,2}[^\+]*)(?:\+.*)?$' [tool.ruff] lint.extend-select = ["I"] target-version = "py39" +fix = true [tool.ruff.lint.isort] force-single-line = true From 3598c654e3849ecc7126ec11e745827bec71b5bd Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Fri, 1 Nov 2024 10:04:18 -0400 Subject: [PATCH 3/3] Support `pa.Array` in `IndexLike`/`IndexFactory` --- python-spec/src/somacore/query/_fast_csr.py | 4 ++-- python-spec/src/somacore/query/types.py | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/python-spec/src/somacore/query/_fast_csr.py b/python-spec/src/somacore/query/_fast_csr.py index 511547a3..9927e274 100644 --- a/python-spec/src/somacore/query/_fast_csr.py +++ b/python-spec/src/somacore/query/_fast_csr.py @@ -82,8 +82,8 @@ class _CSRAccumulator: def __init__( self, - obs_joinids: npt.NDArray[np.int64], - var_joinids: npt.NDArray[np.int64], + obs_joinids: pa.Array, + var_joinids: pa.Array, pool: futures.Executor, index_factory: types.IndexFactory, ): diff --git a/python-spec/src/somacore/query/types.py b/python-spec/src/somacore/query/types.py index ca9d8de6..6ffbba74 100644 --- a/python-spec/src/somacore/query/types.py +++ b/python-spec/src/somacore/query/types.py @@ -1,11 +1,14 @@ """Common types used across SOMA query modules.""" -from typing import Any, Callable +from typing import Any, Callable, Union import numpy as np import numpy.typing as npt +import pyarrow as pa from typing_extensions import Protocol +_Array = Union[npt.NDArray[np.int64], pa.Array] + class IndexLike(Protocol): """The basics of what we expect an Index to be. @@ -16,11 +19,11 @@ class IndexLike(Protocol): not as a full specification of the types and behavior of ``get_indexer``. """ - def get_indexer(self, target: npt.NDArray[np.int64]) -> Any: + def get_indexer(self, target: _Array) -> Any: """Something compatible with Pandas' Index.get_indexer method.""" -IndexFactory = Callable[[npt.NDArray[np.int64]], "IndexLike"] +IndexFactory = Callable[[_Array], "IndexLike"] """Function that builds an index over the given NDArray. This interface is implemented by the callable ``pandas.Index``.