Skip to content

Commit

Permalink
Make some Experiment/Query classes abstract (#244)
Browse files Browse the repository at this point in the history
* make `{experiment,query}.py` classes abstract

* `rm _{{test_,}eager_iter,fast_csr}.py` (moved to TileDB-SOMA)

* `ExperimentAxisQuery`, `AxisIndexer` are explicitly `ABC`s

* rm `somacore.ephemeral` (and associated tests)
  • Loading branch information
ryan-williams authored Nov 18, 2024
1 parent 415c32b commit 99b22f9
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 1,451 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ readme = "./python-spec/README.md"
dependencies = [
"anndata",
"attrs>=22.1",
"numba",
"numpy>=1.21",
"pandas",
"pyarrow",
Expand Down
1 change: 0 additions & 1 deletion python-spec/requirements-py3.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ exceptiongroup==1.2.1
h5py==3.11.0
llvmlite==0.43.0
natsort==8.4.0
numba==0.60.0
numpy==2.0.0
packaging==24.1
pandas==2.2.2
Expand Down
1 change: 0 additions & 1 deletion python-spec/requirements-py3.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ attrs==23.2.0
h5py==3.11.0
llvmlite==0.43.0
natsort==8.4.0
numba==0.60.0
numpy==2.0.0
packaging==24.1
pandas==2.2.2
Expand Down
1 change: 0 additions & 1 deletion python-spec/requirements-py3.12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ attrs==23.2.0
h5py==3.11.0
llvmlite==0.43.0
natsort==8.4.0
numba==0.60.0
numpy==2.0.0
packaging==24.1
pandas==2.2.2
Expand Down
1 change: 0 additions & 1 deletion python-spec/requirements-py3.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ h5py==3.11.0
jmespath==1.0.1
llvmlite==0.43.0
natsort==8.4.0
numba==0.60.0
numpy==2.0.0
packaging==24.1
pandas==2.2.2
Expand Down
18 changes: 0 additions & 18 deletions python-spec/src/somacore/ephemeral/__init__.py

This file was deleted.

234 changes: 0 additions & 234 deletions python-spec/src/somacore/ephemeral/collections.py

This file was deleted.

39 changes: 11 additions & 28 deletions python-spec/src/somacore/experiment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from abc import ABC
from abc import abstractmethod
from typing import Generic, Optional, TypeVar

from typing_extensions import Final, Self
from typing_extensions import Final

from . import _mixin
from . import base
Expand All @@ -9,6 +11,7 @@
from . import measurement
from . import query
from . import scene
from .query import ExperimentAxisQuery

_DF = TypeVar("_DF", bound=data.DataFrame)
"""An implementation of a DataFrame."""
Expand All @@ -20,8 +23,10 @@
"""The root SOMA object type of the implementation."""


class Experiment(
collection.BaseCollection[_RootSO], Generic[_DF, _MeasColl, _SceneColl, _RootSO]
class Experiment( # type: ignore[misc] # __eq__ false positive
collection.BaseCollection[_RootSO],
Generic[_DF, _MeasColl, _SceneColl, _RootSO],
ABC,
):
"""A collection subtype representing an annotated 2D matrix of measurements.
Expand All @@ -33,22 +38,6 @@ class Experiment(
Lifecycle: maturing
"""

# This class is implemented as a mixin to be used with SOMA classes.
# For example, a SOMA implementation would look like this:
#
# # This type-ignore comment will always be needed due to limitations
# # of type annotations; it is (currently) expected.
# class Experiment( # type: ignore[type-var]
# ImplBaseCollection[ImplSOMAObject],
# somacore.Experiment[
# ImplDataFrame, # _DF
# ImplMeasurement, # _MeasColl
# ImplScene, # _SceneColl
# ImplSOMAObject, # _RootSO
# ],
# ):
# ...

__slots__ = ()
soma_type: Final = "SOMAExperiment" # type: ignore[misc]

Expand Down Expand Up @@ -77,24 +66,18 @@ class Experiment(
``scene_id`` and ``False`` otherwise.
"""

@abstractmethod
def axis_query(
self,
measurement_name: str,
*,
obs_query: Optional[query.AxisQuery] = None,
var_query: Optional[query.AxisQuery] = None,
) -> "query.ExperimentAxisQuery[Self]":
) -> ExperimentAxisQuery:
"""Creates an axis query over this experiment.
See :class:`query.ExperimentAxisQuery` for details on usage.
Lifecycle: maturing
"""
# mypy doesn't quite understand descriptors so it issues a spurious
# error here.
return query.ExperimentAxisQuery( # type: ignore[type-var]
self,
measurement_name,
obs_query=obs_query or query.AxisQuery(),
var_query=var_query or query.AxisQuery(),
)
raise NotImplementedError
2 changes: 2 additions & 0 deletions python-spec/src/somacore/query/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

ExperimentAxisQuery = query.ExperimentAxisQuery
AxisColumnNames = query.AxisColumnNames
AxisIndexer = query.AxisIndexer
AxisQuery = axis.AxisQuery

__all__ = (
"ExperimentAxisQuery",
"AxisColumnNames",
"AxisIndexer",
"AxisQuery",
)
Loading

0 comments on commit 99b22f9

Please sign in to comment.