Skip to content

Commit

Permalink
(fix): test for float32 and float64
Browse files Browse the repository at this point in the history
  • Loading branch information
ilan-gold committed Nov 11, 2024
1 parent 98f7bea commit 150d8aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/anndata/_core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def name_idx(i):
indexer = np.array(indexer)
if len(indexer) == 0:
indexer = indexer.astype(int)
if isinstance(indexer, np.ndarray) and indexer.dtype == float:
if isinstance(indexer, np.ndarray) and np.issubdtype(
indexer.dtype, np.floating
):
indexer_int = indexer.astype(int)
if np.all((indexer - indexer_int) != 0):
raise IndexError(f"Indexer {indexer!r} has floating point values.")
Expand Down
5 changes: 4 additions & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,11 @@ def test_index_3d_errors(index: tuple[int | EllipsisType, ...], expected_error:
"index",
[
pytest.param(sparse.csr_matrix(np.random.random((1, 10))), id="sparse"),
pytest.param(np.array([1.2, 2.3]), id="ndarray"),
pytest.param([1.2, 3.4], id="list"),
*(
pytest.param(np.array([1.2, 2.3], dtype=dtype), id=f"ndarray-{dtype}")
for dtype in [np.float32, np.float64]
),
],
)
def test_index_float_sequence_raises_error(index):
Expand Down

0 comments on commit 150d8aa

Please sign in to comment.