-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow overriding of CSR accumulators with an IndexLike. (#181)
To support a custom indexer in TileDB-SOMA, this introduces a basic abstraction that is used to build the Indexer used by the CSR Accumulator. This can then be easily overridden by an implementation's custom subclass to swap that out without having to duplicate substantial parts of the code. The naming is, admittedly, not ideal; this is in part due to the naming of the things we're trying to abstract over (the Pandas `Index` type which has the `get_indexer` method).
- Loading branch information
1 parent
10dc344
commit a79f984
Showing
3 changed files
with
101 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Common types used across SOMA query modules.""" | ||
|
||
from typing import Any, Callable | ||
|
||
import numpy as np | ||
import numpy.typing as npt | ||
from typing_extensions import Protocol | ||
|
||
|
||
class IndexLike(Protocol): | ||
"""The basics of what we expect an Index to be. | ||
This is a basic description of the parts of the ``pandas.Index`` type | ||
that we use. It is intended as a rough guide so an implementor can know | ||
that they are probably passing the right "index" type into a function, | ||
not as a full specification of the types and behavior of ``get_indexer``. | ||
""" | ||
|
||
def get_indexer( | ||
self, | ||
target: npt.NDArray[np.int64], | ||
method: object = ..., | ||
limit: object = ..., | ||
tolerance: object = ..., | ||
) -> Any: | ||
"""Something compatible with Pandas' Index.get_indexer method.""" | ||
|
||
|
||
IndexFactory = Callable[[npt.NDArray[np.int64]], "IndexLike"] | ||
"""Function that builds an index over the given NDArray. | ||
This interface is implemented by the callable ``pandas.Index``. | ||
""" |