Skip to content

Commit

Permalink
Make coords for reading DataFrame and SparseNDArray optional. (#97)
Browse files Browse the repository at this point in the history
The TileDB implementation currently has `coords` as an optional,
default-None value for reads of DataFrames and SparseNDArrays.
This updates the ABCs to match that reality.
  • Loading branch information
thetorpedodog authored Jan 24, 2023
1 parent 3dc0942 commit 3588866
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 8 additions & 6 deletions python-spec/src/somacore/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ def create(
@abc.abstractmethod
def read(
self,
coords: options.SparseDFCoords,
coords: Optional[options.SparseDFCoords] = None,
column_names: Optional[Sequence[str]] = None,
*,
batch_size: options.BatchSize = options.BatchSize(),
partitions: Optional[options.ReadPartitions] = None,
result_order: options.StrOr[options.ResultOrder] = _RO_AUTO,
result_order: options.ResultOrderStr = _RO_AUTO,
value_filter: Optional[str] = None,
platform_config: Optional[options.PlatformConfig] = None,
) -> "ReadIter[pa.Table]":
Expand All @@ -66,6 +66,7 @@ def read(
def write(
self,
values: Union[pa.RecordBatch, pa.Table],
*,
platform_config: Optional[options.PlatformConfig] = None,
) -> None:
"""Writes values to the data store.
Expand Down Expand Up @@ -109,7 +110,8 @@ class NDArray(base.SOMAObject, metaclass=abc.ABCMeta):
def create(
cls: Type[_NDT],
uri: str,
*type: pa.DataType,
*,
type: pa.DataType,
shape: Sequence[int],
platform_config: Optional[options.PlatformConfig] = None,
context: Optional[Any] = None,
Expand Down Expand Up @@ -155,7 +157,7 @@ def read(
*,
batch_size: options.BatchSize = options.BatchSize(),
partitions: Optional[options.ReadPartitions] = None,
result_order: options.StrOr[options.ResultOrder] = _RO_AUTO,
result_order: options.ResultOrderStr = _RO_AUTO,
platform_config: Optional[options.PlatformConfig] = None,
) -> pa.Tensor:
"""Reads the specified subarray from this NDArray as a Tensor.
Expand Down Expand Up @@ -199,11 +201,11 @@ class SparseNDArray(NDArray, metaclass=abc.ABCMeta):
@abc.abstractmethod
def read(
self,
coords: options.SparseNDCoords,
coords: Optional[options.SparseNDCoords] = None,
*,
batch_size: options.BatchSize = options.BatchSize(),
partitions: Optional[options.ReadPartitions] = None,
result_order: options.StrOr[options.ResultOrder] = _RO_AUTO,
result_order: options.ResultOrderStr = _RO_AUTO,
platform_config: Optional[options.PlatformConfig] = None,
) -> "SparseRead":
"""Reads a subset of the object in one or more batches.
Expand Down
10 changes: 5 additions & 5 deletions python-spec/src/somacore/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

import enum
from typing import Any, Mapping, Optional, Sequence, TypeVar, Union
from typing import Any, Mapping, Optional, Sequence, Union

import attrs
import numpy as np
Expand Down Expand Up @@ -96,10 +96,6 @@ def _validate(self, attr: attrs.Attribute, value):
an implementation-defined configuration structure.
"""

_ET = TypeVar("_ET", bound=enum.Enum)
StrOr = Union[_ET, str]
"""A string, or the named enum."""


class ResultOrder(enum.Enum):
"""The order results should be returned in."""
Expand All @@ -109,6 +105,10 @@ class ResultOrder(enum.Enum):
COLUMN_MAJOR = "column-major"


ResultOrderStr = Union[ResultOrder, Literal["auto", "row-major", "column-major"]]
"""A ResultOrder, or the str representing it."""


DenseCoord = Union[int, slice]
"""A single coordinate range for reading dense data."""
DenseNDCoords = Sequence[DenseCoord]
Expand Down

0 comments on commit 3588866

Please sign in to comment.