Skip to content

Commit

Permalink
[python] Add support for timestamp types in axis query (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl authored Feb 23, 2023
1 parent 0e448f3 commit 0c4939d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions python-spec/src/somacore/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,15 @@ class ResultOrder(enum.Enum):
Sequence[float],
Sequence[str],
Sequence[bytes],
Sequence[npt.NDArray[np.datetime64]],
types.Slice[float],
types.Slice[str],
types.Slice[bytes],
types.Slice[npt.NDArray[np.datetime64]],
pa.Array,
pa.ChunkedArray,
npt.NDArray[np.integer],
npt.NDArray[np.datetime64],
]
"""A single coordinate range for one dimension of a sparse dataframe."""
SparseDFCoords = Sequence[SparseDFCoord]
Expand Down
13 changes: 12 additions & 1 deletion python-spec/src/somacore/query/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ def _canonicalize_coord(coord: options.SparseDFCoord) -> options.SparseDFCoord:
# NOTE: Keep this in sync with the `SparseDFCoord` type.
if coord is None or isinstance(
coord,
(bytes, float, int, slice, str, pa.Array, pa.ChunkedArray, np.ndarray),
(
bytes,
float,
int,
slice,
str,
pa.Array,
pa.ChunkedArray,
np.ndarray,
np.datetime64,
pa.lib.TimestampType,
),
):
return coord
if isinstance(coord, Sequence):
Expand Down
4 changes: 4 additions & 0 deletions python-spec/testing/test_query_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
([1, 1.5, 2], (1, 1.5, 2)),
((slice(None), [0, 88, 1001]), (slice(None), (0, 88, 1001))),
((slice(2.5, 3.5),), (slice(2.5, 3.5),)),
(
(slice(np.datetime64(946684802, "s"), np.datetime64(946684803, "s")),),
(slice(np.datetime64(946684802, "s"), np.datetime64(946684803, "s")),),
),
(("string-coord", [b"lo", b"hi"]), ("string-coord", (b"lo", b"hi"))),
],
)
Expand Down

0 comments on commit 0c4939d

Please sign in to comment.