Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Jan 31, 2024
1 parent fc51665 commit 26c9534
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 4 additions & 2 deletions apis/python/src/tiledbsoma/_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from ._collection import Collection, CollectionBase
from ._dataframe import DataFrame
from ._index_util import build_index
from ._index_util import tiledbsoma_build_index
from ._measurement import Measurement
from ._tdb_handles import Wrapper
from ._tiledb_object import AnyTileDBObject
Expand Down Expand Up @@ -94,5 +94,7 @@ def axis_query( # type: ignore
measurement_name,
obs_query=obs_query or query.AxisQuery(),
var_query=var_query or query.AxisQuery(),
index_factory=functools.partial(build_index, context=self.context),
index_factory=functools.partial(
tiledbsoma_build_index, context=self.context
),
)
15 changes: 10 additions & 5 deletions apis/python/src/tiledbsoma/_index_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
SOMATileDBContext which would otherwise ensue.
"""

from typing import Optional

import numpy as np
import pandas as pd

Expand All @@ -11,17 +13,20 @@
from .options import SOMATileDBContext


def build_index(
keys: np.typing.NDArray[np.int64], context: SOMATileDBContext
def tiledbsoma_build_index(
keys: np.typing.NDArray[np.int64],
context: Optional[SOMATileDBContext],
) -> clib.IntIndexer:
"""Builds an indexer object compatible with :meth:`pd.Index.get_indexer`."""
if len(np.unique(keys)) != len(keys):
raise pd.errors.InvalidIndexError(
"Reindexing only valid with uniquely valued Index objects"
)
tdb_concurrency = int(
context.tiledb_ctx.config().get("sm.compute_concurrency_level", 10)
)
tdb_concurrency = 10
if context is not None:
tdb_concurrency = int(
context.tiledb_ctx.config().get("sm.compute_concurrency_level", 10)
)
thread_count = tdb_concurrency // 2
reindexer = clib.IntIndexer()
reindexer.map_locations(keys, thread_count)
Expand Down
6 changes: 3 additions & 3 deletions apis/python/tests/test_indexer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pandas as pd

from tiledbsoma._index_util import build_index
from tiledbsoma._index_util import tiledbsoma_build_index
from tiledbsoma.options import SOMATileDBContext
from tiledbsoma.options._soma_tiledb_context import _validate_soma_tiledb_context

Expand All @@ -16,7 +16,7 @@ def indexer_test(keys: np.array, lookups: np.array, fail: bool):
def indexer_test_fail(keys: np.array, lookups: np.array):
try:
context = _validate_soma_tiledb_context(SOMATileDBContext())
index = build_index(keys, context)
index = tiledbsoma_build_index(keys, context)
index.get_indexer(lookups)
raise AssertionError("should have failed")
except pd.errors.InvalidIndexError:
Expand All @@ -32,7 +32,7 @@ def indexer_test_fail(keys: np.array, lookups: np.array):

def indexer_test_pass(keys: np.array, lookups: np.array):
context = _validate_soma_tiledb_context(SOMATileDBContext())
indexer = build_index(keys, context)
indexer = tiledbsoma_build_index(keys, context)
results = indexer.get_indexer(lookups)
panda_indexer = pd.Index(keys)
panda_results = panda_indexer.get_indexer(lookups)
Expand Down

0 comments on commit 26c9534

Please sign in to comment.