Skip to content

Commit 88efa30

Browse files
committed
Adds a test for different types of arrays.
1 parent ae403ee commit 88efa30

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

test/test_util.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,22 +384,32 @@ def test_dtype_from_element_str_and_bytes_dtypes(self) -> None:
384384

385385
def test_get_new_indexers_and_screen_a(self) -> None:
386386
indexersA = np.array([9, 9, 9, 9, 0, 0, 1, 4, 5, 0, 0, 0, 1], dtype=np.int64)
387-
postB = get_new_indexers_and_screen_ak(indexersA, np.arange(10, dtype=np.int64))
388-
assert tuple(map(list, postB)) == (
387+
postA = get_new_indexers_and_screen_ak(indexersA, np.arange(10, dtype=np.int64))
388+
assert indexersA.flags.c_contiguous
389+
assert indexersA.flags.f_contiguous
390+
assert tuple(map(list, postA)) == (
389391
[0, 0, 0, 0, 1, 1, 2, 3, 4, 1, 1, 1, 2],
390392
[9, 0, 1, 4, 5],
391393
)
392394

393-
indexersB = np.array([9, 9, 9, 9, 0, 0, 1, 4, 5, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], dtype=np.int64)
394-
postB = get_new_indexers_and_screen_ak(indexersB, positions=np.arange(15, dtype=np.int64))
395-
assert tuple(map(list, postB)) == (
395+
# Prove we can handle non-continuous arrays
396+
indexersB = np.full((len(indexersA), 3), -1)
397+
indexersB[:,1] = indexersA.copy()
398+
assert not indexersB[:,1].flags.c_contiguous
399+
assert not indexersB[:,1].flags.f_contiguous
400+
postB = get_new_indexers_and_screen_ak(indexersB[:,1], np.arange(10, dtype=np.int64))
401+
assert tuple(map(list, postA)) == tuple(map(list, postB))
402+
403+
indexersC = np.array([9, 9, 9, 9, 0, 0, 1, 4, 5, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], dtype=np.int64)
404+
postC = get_new_indexers_and_screen_ak(indexersC, positions=np.arange(15, dtype=np.int64))
405+
assert tuple(map(list, postC)) == (
396406
[0, 0, 0, 0, 1, 1, 2, 3, 4, 1, 1, 1, 2, 5, 6, 3, 4,7, 8, 9, 0, 10],
397407
[9, 0, 1, 4, 5, 2, 3, 6, 7, 8, 10],
398408
)
399409

400-
indexersC = np.array([2, 1, 0, 2, 0, 1, 1, 2, 0], dtype=np.int64)
401-
postC = get_new_indexers_and_screen_ak(indexers=indexersC, positions=np.arange(3, dtype=np.int64))
402-
assert tuple(map(list, postC)) == (
410+
indexersD = np.array([2, 1, 0, 2, 0, 1, 1, 2, 0], dtype=np.int64)
411+
postD = get_new_indexers_and_screen_ak(indexers=indexersD, positions=np.arange(3, dtype=np.int64))
412+
assert tuple(map(list, postD)) == (
403413
[2, 1, 0, 2, 0, 1, 1, 2, 0],
404414
[0, 1, 2],
405415
)

0 commit comments

Comments
 (0)