Skip to content

Commit

Permalink
fix casting bug (#3525)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkmartinjr authored Jan 7, 2025
1 parent 34c3618 commit 2fb542d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions apis/python/src/tiledbsoma/_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ def __init__(

# TODO: the map_locations interface does not accept chunked arrays. It would
# save a copy (reduce memory usage) if they were natively supported.
if isinstance(
data, (pa.Array, pa.ChunkedArray, pd.arrays.IntegerArray, pd.Series)
):
if isinstance(data, (pa.Array, pa.ChunkedArray)):
data = data.to_numpy()
elif isinstance(data, list):
data = np.array(data, dtype=np.int64)
elif isinstance(data, (pd.arrays.IntegerArray, pd.Series)):
data = data.to_numpy(dtype=np.int64, copy=False)

self._reindexer.map_locations(data)

Expand All @@ -95,7 +95,7 @@ def get_indexer(self, target: IndexerDataType) -> npt.NDArray[np.intp]:
return self._reindexer.get_indexer_pyarrow(target)

if isinstance(target, (pd.arrays.IntegerArray, pd.Series)):
target = target.to_numpy()
target = target.to_numpy(dtype=np.int64, copy=False)
elif isinstance(target, list):
target = np.array(target, dtype=np.int64)

Expand Down
11 changes: 8 additions & 3 deletions apis/python/tests/test_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,12 @@ def test_indexer(contextual: bool, keys: np.array, lookups: np.array):
num_threads = 10

def target():
indexer = IntIndexer(keys, context=context)
results = indexer.get_indexer(lookups)
all_results.append(results)
try:
indexer = IntIndexer(keys, context=context)
results = indexer.get_indexer(lookups)
all_results.append(results)
except Exception as e:
all_results.append(e)

for t in range(num_threads):
thread = threading.Thread(target=target, args=())
Expand All @@ -113,6 +116,8 @@ def target():
panda_indexer = pd.Index(keys)
panda_results = panda_indexer.get_indexer(lookups)
for i in range(num_threads):
if isinstance(all_results[i], Exception):
raise all_results[i]
np.testing.assert_equal(all_results[i].all(), panda_results.all())


Expand Down

0 comments on commit 2fb542d

Please sign in to comment.