Skip to content

Commit

Permalink
make {experiment,query}.py classes abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-williams committed Nov 7, 2024
1 parent 6243608 commit 1337815
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 718 deletions.
2 changes: 2 additions & 0 deletions python-spec/src/somacore/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ def write(
Arrow table: a COO table, with columns named ``soma_dim_0``,
..., ``soma_dim_N`` and ``soma_data``.
platform_config: platform-specific configuration; keys are SOMA
implementation names.
Returns: ``self``, to enable method chaining.
Expand Down
37 changes: 9 additions & 28 deletions python-spec/src/somacore/experiment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import abc
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 +10,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 +22,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.ABC,
):
"""A collection subtype representing an annotated 2D matrix of measurements.
Expand All @@ -33,22 +37,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 @@ -83,18 +71,11 @@ def axis_query(
*,
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 1337815

Please sign in to comment.