Skip to content

Commit

Permalink
ingest somacore classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-williams committed Nov 7, 2024
1 parent 9d93ac3 commit 6244a5a
Show file tree
Hide file tree
Showing 6 changed files with 925 additions and 59 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ repos:
# Pandas 2.x types (e.g. `pd.Series[Any]`). See `_types.py` or https://github.com/single-cell-data/TileDB-SOMA/issues/2839
# for more info.
- "pandas-stubs>=2"
- "somacore==1.0.23"
# Temporary, for PR: see https://github.com/single-cell-data/SOMA/pull/244
- "git+https://github.com/single-cell-data/soma@9e81f07"
- types-setuptools
args: ["--config-file=apis/python/pyproject.toml", "apis/python/src", "apis/python/devtools"]
pass_filenames: false
4 changes: 2 additions & 2 deletions apis/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ def run(self):
"pyarrow",
"scanpy>=1.9.2",
"scipy",
# Note: the somacore version is in .pre-commit-config.yaml too
"somacore==1.0.23",
# Temporary, for PR: see https://github.com/single-cell-data/SOMA/pull/244
"somacore @ git+https://github.com/single-cell-data/soma@rw/abcs",
"typing-extensions", # Note "-" even though `import typing_extensions`
],
extras_require={
Expand Down
8 changes: 3 additions & 5 deletions apis/python/src/tiledbsoma/_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from typing import Optional

from somacore import experiment, query
from typing_extensions import Self

from . import _tdb_handles
from ._collection import Collection, CollectionBase
from ._dataframe import DataFrame
from ._indexer import IntIndexer
from ._measurement import Measurement
from ._query import ExperimentAxisQuery
from ._scene import Scene
from ._soma_object import AnySOMAObject

Expand Down Expand Up @@ -83,13 +83,11 @@ def axis_query( # type: ignore
*,
obs_query: Optional[query.AxisQuery] = None,
var_query: Optional[query.AxisQuery] = None,
) -> query.ExperimentAxisQuery[Self]: # type: ignore
) -> ExperimentAxisQuery:
"""Creates an axis query over this experiment.
Lifecycle: Maturing.
"""
# mypy doesn't quite understand descriptors so it issues a spurious
# error here.
return query.ExperimentAxisQuery( # type: ignore
return ExperimentAxisQuery(
self,
measurement_name,
obs_query=obs_query or query.AxisQuery(),
Expand Down
14 changes: 6 additions & 8 deletions apis/python/src/tiledbsoma/_indexer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, List, Optional, Union
from typing import List, Optional, Union

import numpy as np
import numpy.typing as npt
Expand All @@ -11,9 +11,7 @@
from tiledbsoma import pytiledbsoma as clib

from ._types import PDSeries

if TYPE_CHECKING:
from .options import SOMATileDBContext
from .options import SOMATileDBContext

IndexerDataType = Union[
npt.NDArray[np.int64],
Expand All @@ -27,7 +25,7 @@


def tiledbsoma_build_index(
data: IndexerDataType, *, context: Optional["SOMATileDBContext"] = None
data: IndexerDataType, *, context: Optional[SOMATileDBContext] = None
) -> IndexLike:
"""Initialize re-indexer for provided indices (deprecated).
Expand All @@ -54,7 +52,7 @@ class IntIndexer:
"""

def __init__(
self, data: IndexerDataType, *, context: Optional["SOMATileDBContext"] = None
self, data: IndexerDataType, *, context: Optional[SOMATileDBContext] = None
):
"""Initialize re-indexer for provided indices.
Expand All @@ -73,15 +71,15 @@ def __init__(
)
self._reindexer.map_locations(data)

def get_indexer(self, target: IndexerDataType) -> Any:
def get_indexer(self, target: IndexerDataType) -> npt.NDArray[np.intp]:
"""Compute underlying indices of index for target data.
Compatible with Pandas' Index.get_indexer method.
Args:
target: Data to return re-index data for.
"""
return (
return ( # type: ignore[no-any-return]
self._reindexer.get_indexer_pyarrow(target)
if isinstance(target, (pa.Array, pa.ChunkedArray))
else self._reindexer.get_indexer_general(target)
Expand Down
Loading

0 comments on commit 6244a5a

Please sign in to comment.