From 22851b29d81386d4f52302bf4fbb87b47d39db68 Mon Sep 17 00:00:00 2001 From: Amanda Potts Date: Mon, 30 Dec 2024 15:34:41 -0500 Subject: [PATCH] Closes #3954: skip_by_rank to handle set containment --- pytest.ini | 1 + tests/array_api/array_creation.py | 12 +++++----- tests/array_api/array_manipulation.py | 22 +++++++++--------- tests/array_api/array_object.py | 2 +- tests/array_api/binary_ops.py | 2 +- tests/array_api/elementwise_functions.py | 2 +- tests/array_api/indexing.py | 8 +++---- tests/array_api/linalg.py | 6 ++--- tests/array_api/searching_functions.py | 10 ++++---- tests/array_api/set_functions.py | 4 ++-- tests/array_api/sorting.py | 4 ++-- tests/array_api/stats_functions.py | 16 ++++++------- tests/array_api/util_functions.py | 14 +++++------ tests/array_manipulation_tests.py | 4 ++-- tests/conftest.py | 25 +++++++++++++++++--- tests/numpy/manipulation_functions_test.py | 6 ++--- tests/numpy/numeric_test.py | 27 +++++++++++----------- tests/numpy/utils_test.py | 2 +- tests/pdarray_creation_test.py | 20 ++++++++-------- tests/pdarrayclass_test.py | 18 +++++++-------- tests/testing/asserters_test.py | 8 +++---- 21 files changed, 117 insertions(+), 96 deletions(-) diff --git a/pytest.ini b/pytest.ini index d6cb0bfd0f..130dea4206 100644 --- a/pytest.ini +++ b/pytest.ini @@ -74,5 +74,6 @@ env = markers = skip_if_max_rank_less_than skip_if_max_rank_greater_than + skip_if_rank_not_compiled skip_if_nl_greater_than skip_if_nl_less_than diff --git a/tests/array_api/array_creation.py b/tests/array_api/array_creation.py index 99af74cb29..6c2812bf85 100644 --- a/tests/array_api/array_creation.py +++ b/tests/array_api/array_creation.py @@ -15,21 +15,21 @@ class TestArrayCreation: - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("shape", SHAPES) @pytest.mark.parametrize("dtype", ak.ScalarDTypes) def test_zeros(self, shape, dtype): a = xp.zeros(shape, dtype=dtype) assert_equivalent(a._array, np.zeros(shape, dtype=dtype)) - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("shape", SHAPES) @pytest.mark.parametrize("dtype", ak.ScalarDTypes) def test_ones(self, shape, dtype): a = xp.ones(shape, dtype=dtype) assert_equivalent(a._array, np.ones(shape, dtype=dtype)) - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) def test_from_numpy(self): # TODO: support 0D (scalar) arrays # (need changes to the create0D command from #2967) @@ -41,7 +41,7 @@ def test_from_numpy(self): assert b.shape == a.shape assert b.tolist() == a.tolist() - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("data_type", [ak.int64, ak.float64, ak.bool_]) @pytest.mark.parametrize("prob_size", pytest.prob_size) def test_triu(self, data_type, prob_size): @@ -60,7 +60,7 @@ def test_triu(self, data_type, prob_size): ak_triu = array_triu(pda, k=diag)._array assert_almost_equivalent(ak_triu, np_triu) - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("data_type", [ak.int64, ak.float64, ak.bool_]) @pytest.mark.parametrize("prob_size", pytest.prob_size) def test_tril(self, data_type, prob_size): @@ -79,7 +79,7 @@ def test_tril(self, data_type, prob_size): ak_tril = array_tril(pda, k=diag)._array assert_almost_equivalent(np_tril, ak_tril) - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("data_type", [ak.int64, ak.float64, ak.bool_]) @pytest.mark.parametrize("prob_size", pytest.prob_size) def test_eye(self, data_type, prob_size): diff --git a/tests/array_api/array_manipulation.py b/tests/array_api/array_manipulation.py index 7dc3c57937..96e0e81193 100644 --- a/tests/array_api/array_manipulation.py +++ b/tests/array_api/array_manipulation.py @@ -18,7 +18,7 @@ def randArr(shape): class TestManipulation: - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_broadcast(self): a = xp.ones((1, 6, 1)) b = xp.ones((5, 1, 10)) @@ -37,7 +37,7 @@ def test_broadcast(self): assert (abcd[2] == 1).all() assert (abcd[3] == 1).all() - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_concat(self): a = randArr((5, 3, 10)) b = randArr((5, 3, 2)) @@ -70,7 +70,7 @@ def test_concat(self): assert hijConcat.shape == (18,) assert hijConcat.tolist() == hijNP.tolist() - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_expand_dims(self): a = randArr((5, 3)) alist = a.tolist() @@ -105,7 +105,7 @@ def test_expand_dims(self): with pytest.raises(IndexError): xp.expand_dims(a, axis=-4) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) def test_flip(self): # 1D case a = xp.arange(10) @@ -145,7 +145,7 @@ def test_flip(self): with pytest.raises(IndexError): xp.flip(r, axis=-4) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) def test_permute_dims(self): r = randArr((7, 8, 9)) @@ -172,7 +172,7 @@ def test_permute_dims(self): with pytest.raises(IndexError): xp.permute_dims(r, (0, 1, -4)) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_reshape(self): r = randArr((2, 6, 12)) nr = np.asarray(r.tolist()) @@ -201,7 +201,7 @@ def test_reshape(self): # more than one dimension can't be inferred xp.reshape(r, (2, -1, -1)) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) def test_roll(self): # 1D case a = xp.arange(10) @@ -244,7 +244,7 @@ def test_roll(self): with pytest.raises(IndexError): xp.roll(r, 3, axis=-4) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_squeeze(self): r1 = randArr((1, 2, 3)) r2 = randArr((2, 1, 3)) @@ -277,7 +277,7 @@ def test_squeeze(self): with pytest.raises(ValueError): xp.squeeze(r4, axis=1) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_stack_unstack(self): a = randArr((5, 4)) b = randArr((5, 4)) @@ -303,7 +303,7 @@ def test_stack_unstack(self): assert bp.tolist() == b.tolist() assert cp.tolist() == c.tolist() - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_tile(self): a = randArr((2, 3)) @@ -313,7 +313,7 @@ def test_tile(self): assert at.shape == npat.shape assert at.tolist() == npat.tolist() - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2]) def test_repeat(self): a = randArr((5, 10)) r = randArr((50,)) diff --git a/tests/array_api/array_object.py b/tests/array_api/array_object.py index 329f54fd59..1705ee65f2 100644 --- a/tests/array_api/array_object.py +++ b/tests/array_api/array_object.py @@ -13,7 +13,7 @@ def test_chunk_info(self): assert chunks == [[0]] @pytest.mark.skipif(pytest.nl > 1, reason="Multi-local will produce different chunk_info") - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) def test_chunk_info_2dim(self): a = xp.zeros((2, 2)) diff --git a/tests/array_api/binary_ops.py b/tests/array_api/binary_ops.py index 006d71fb17..de85017fa7 100644 --- a/tests/array_api/binary_ops.py +++ b/tests/array_api/binary_ops.py @@ -15,7 +15,7 @@ class TestArrayCreation: - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("op", ["+", "-", "*", "/"]) @pytest.mark.parametrize("dtype", SCALAR_TYPES) def test_binops(self, op, dtype): diff --git a/tests/array_api/elementwise_functions.py b/tests/array_api/elementwise_functions.py index 58fea13dd5..226ba25e80 100644 --- a/tests/array_api/elementwise_functions.py +++ b/tests/array_api/elementwise_functions.py @@ -11,7 +11,7 @@ class TestElemenwiseFunctions: - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) def test_logical_not(self): a = xp.asarray(ak.array([True, False, True, False])) not_a = xp.asarray(ak.array([False, True, False, True])) diff --git a/tests/array_api/indexing.py b/tests/array_api/indexing.py index 07cb517bd1..9522004320 100644 --- a/tests/array_api/indexing.py +++ b/tests/array_api/indexing.py @@ -17,7 +17,7 @@ def randArr(shape): class TestIndexing: - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_rank_changing_assignment(self): a = randArr((5, 6, 7)) b = randArr((5, 6)) @@ -37,7 +37,7 @@ def test_rank_changing_assignment(self): a[:, :, :] = e assert a.tolist() == e.tolist() - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) def test_nd_assignment(self): a = randArr((5, 6, 7)) bnp = randArr((5, 6, 7)).to_ndarray() @@ -51,7 +51,7 @@ def test_nd_assignment(self): a[:] = 5 assert (a == 5).all() - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_pdarray_index(self): a = randArr((5, 6, 7)) anp = np.asarray(a.tolist()) @@ -82,7 +82,7 @@ def test_pdarray_index(self): xnp = anp[:] assert x.tolist() == xnp.tolist() - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_none_index(self): a = randArr((10, 10)) anp = np.asarray(a.tolist()) diff --git a/tests/array_api/linalg.py b/tests/array_api/linalg.py index 71d1fea024..50e283dd1c 100644 --- a/tests/array_api/linalg.py +++ b/tests/array_api/linalg.py @@ -8,7 +8,7 @@ class TestLinalg: - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("data_type1", [ak.int64, ak.float64, ak.bool_]) @pytest.mark.parametrize("data_type2", [ak.int64, ak.float64, ak.bool_]) @pytest.mark.parametrize("prob_size", pytest.prob_size) @@ -27,7 +27,7 @@ def test_matmul(self, data_type1, data_type2, prob_size): npProduct = np.matmul(ndaLeft, ndaRight) assert_almost_equivalent(akProduct._array, npProduct) - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("data_type", [ak.int64, ak.float64, ak.bool_]) @pytest.mark.parametrize("prob_size", pytest.prob_size) def test_transpose(self, data_type, prob_size): @@ -43,7 +43,7 @@ def test_transpose(self, data_type, prob_size): ppa = xp.matrix_transpose(array)._array assert np.allclose(ppa.to_ndarray(), npa) - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("data_type1", [ak.int64, ak.float64, ak.bool_]) @pytest.mark.parametrize("data_type2", [ak.int64, ak.float64]) @pytest.mark.parametrize("prob_size", pytest.prob_size) diff --git a/tests/array_api/searching_functions.py b/tests/array_api/searching_functions.py index 7a8ea99bd5..ff4843deec 100644 --- a/tests/array_api/searching_functions.py +++ b/tests/array_api/searching_functions.py @@ -10,7 +10,7 @@ class TestSearchingFunctions: - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_argmax(self): a = xp.asarray(ak.randint(0, 100, (4, 5, 6), dtype=ak.int64, seed=SEED)) a[3, 2, 1] = 101 @@ -27,7 +27,7 @@ def test_argmax(self): assert aArgmax1Keepdims.shape == (4, 1, 6) assert aArgmax1Keepdims[3, 0, 1] == 2 - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_argmin(self): a = xp.asarray(ak.randint(0, 100, (4, 5, 6), dtype=ak.int64, seed=SEED)) a[3, 2, 1] = -1 @@ -42,7 +42,7 @@ def test_argmin(self): assert aArgmin1Keepdims.shape == (4, 1, 6) assert aArgmin1Keepdims[3, 0, 1] == 2 - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) def test_nonzero(self): a = xp.zeros((40, 15, 16), dtype=ak.int64) a[0, 1, 0] = 1 @@ -75,7 +75,7 @@ def test_nonzero_1d(self): assert nz[0].tolist() == [0, 12, 100, 205, 490] - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) def test_where(self): a = xp.zeros((4, 5, 6), dtype=ak.int64) a[1, 2, 3] = 1 @@ -94,7 +94,7 @@ def test_where(self): assert d[0, 0, 0] == c[0, 0, 0] assert d[3, 3, 3] == c[3, 3, 3] - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2]) def test_search_sorted(self): a = xp.asarray(ak.randint(0, 100, 1000, dtype=ak.float64)) b = xp.asarray(ak.randint(0, 100, (10, 10), dtype=ak.float64)) diff --git a/tests/array_api/set_functions.py b/tests/array_api/set_functions.py index 60916897cf..936909d9f9 100644 --- a/tests/array_api/set_functions.py +++ b/tests/array_api/set_functions.py @@ -10,9 +10,9 @@ def ret_shapes(): shapes = [1000] - if pytest.max_rank > 1: + if 2 in ak.client.get_array_ranks(): shapes.append((20, 50)) - if pytest.max_rank > 2: + if 3 in ak.client.get_array_ranks(): shapes.append((2, 10, 50)) return shapes diff --git a/tests/array_api/sorting.py b/tests/array_api/sorting.py index d6aa7b0b42..fc7a0d6df6 100644 --- a/tests/array_api/sorting.py +++ b/tests/array_api/sorting.py @@ -14,7 +14,7 @@ class TestArrayCreation: - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) def test_argsort(self): for shape in SHAPES: for dtype in ak.ScalarDTypes: @@ -46,7 +46,7 @@ def test_argsort(self): for j in range(shape[1] - 1): assert a[i, b[i, j]] <= a[i, b[i, j + 1]] - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("dtype", SCALAR_TYPES) @pytest.mark.parametrize("shape", SHAPES) def test_sort(self, dtype, shape): diff --git a/tests/array_api/stats_functions.py b/tests/array_api/stats_functions.py index 6d265eae49..6cd1084bae 100644 --- a/tests/array_api/stats_functions.py +++ b/tests/array_api/stats_functions.py @@ -12,7 +12,7 @@ class TestStatsFunction: - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_max(self): a = xp.asarray(ak.randint(0, 100, (5, 7, 4), dtype=ak.int64, seed=SEED)) a[3, 6, 2] = 101 @@ -31,7 +31,7 @@ def test_max(self): assert aMax02Keepdims.shape == (1, 7, 1) assert aMax02Keepdims[0, 6, 0] == 101 - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_min(self): a = xp.asarray(ak.randint(0, 100, (5, 7, 4), dtype=ak.int64, seed=SEED)) a[3, 6, 2] = -1 @@ -50,7 +50,7 @@ def test_min(self): assert aMin02Keepdims.shape == (1, 7, 1) assert aMin02Keepdims[0, 6, 0] == -1 - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_mean(self): a = xp.ones((10, 5, 5)) a[0, 0, 0] = 251 @@ -76,7 +76,7 @@ def test_mean(self): assert aMean02Keepdims[0, 0, 0] == 2 assert aMean02Keepdims[2, 0, 0] == 2 - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_std(self): a = xp.ones((10, 5, 5), dtype=ak.float64) a[0, 0, 0] = 26 @@ -96,7 +96,7 @@ def test_std(self): assert abs(aStd02Keepdims[0, 0, 0] - math.sqrt(24)) < 1e-10 assert abs(aStd02Keepdims[2, 0, 0] - math.sqrt(24)) < 1e-10 - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_var(self): a = xp.ones((10, 5, 5), dtype=ak.float64) a[0, 0, 0] = 26 @@ -116,7 +116,7 @@ def test_var(self): assert abs(aStd02Keepdims[0, 0, 0] - 24) < 1e-10 assert abs(aStd02Keepdims[2, 0, 0] - 24) < 1e-10 - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_prod(self): a = xp.ones((2, 3, 4)) a = a + a @@ -135,7 +135,7 @@ def test_prod(self): assert aProd02Keepdims.shape == (2, 1, 1) assert aProd02Keepdims[0, 0, 0] == 2**12 - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) def test_sum(self): a = xp.ones((2, 3, 4)) @@ -153,7 +153,7 @@ def test_sum(self): assert aSum02Keepdims.shape == (2, 1, 1) assert aSum02Keepdims[0, 0, 0] == 12 - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) def test_cumsum(self): a = xp.asarray(ak.randint(0, 100, (5, 6, 7), seed=SEED)) diff --git a/tests/array_api/util_functions.py b/tests/array_api/util_functions.py index 31acacb9dd..c334460e41 100644 --- a/tests/array_api/util_functions.py +++ b/tests/array_api/util_functions.py @@ -21,7 +21,7 @@ def randArr(shape, dtype): class TestUtilFunctions: - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) def test_all(self): a = xp.ones((10, 10), dtype=ak.bool_) assert xp.all(a) @@ -29,7 +29,7 @@ def test_all(self): a[3, 4] = False assert not xp.all(a) - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) def test_any(self): a = xp.zeros((10, 10), dtype=ak.bool_) assert not xp.any(a) @@ -38,7 +38,7 @@ def test_any(self): assert xp.any(a) @pytest.mark.parametrize("dtype", DTYPES) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) def test_clip(self, dtype): a = randArr((5, 6, 7), dtype) @@ -48,7 +48,7 @@ def test_clip(self, dtype): anp_c = np.clip(anp, 10, 90) assert a_c.tolist() == anp_c.tolist() - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) def test_clip_errors(self): # bool a = xp.asarray(ak.randint(0, 100, (5, 6, 7), dtype=ak.bool_, seed=s), dtype=ak.bool_) @@ -70,7 +70,7 @@ def test_clip_errors(self): xp.clip(a, 10, 90) @pytest.mark.parametrize("dtype", DTYPES) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) def test_diff(self, dtype): a = randArr((5, 6, 7), dtype) anp = a.to_ndarray() @@ -84,7 +84,7 @@ def test_diff(self, dtype): assert a_d.tolist() == anp_d.tolist() - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) def test_diff_error(self): # bool a = xp.asarray(ak.randint(0, 100, (5, 6, 7), dtype=ak.bool_, seed=s), dtype=ak.bool_) @@ -105,7 +105,7 @@ def test_diff_error(self): ): xp.diff(a, n=2, axis=0) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) def test_pad(self): a = xp.ones((5, 6, 7)) anp = np.ones((5, 6, 7)) diff --git a/tests/array_manipulation_tests.py b/tests/array_manipulation_tests.py index 4672272cbb..2a0032b4ec 100644 --- a/tests/array_manipulation_tests.py +++ b/tests/array_manipulation_tests.py @@ -8,7 +8,7 @@ class TestManipulationFunctions: - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) def test_vstack(self): a = [ak.random.randint(0, 10, 25) for _ in range(4)] n = [x.to_ndarray() for x in a] @@ -18,7 +18,7 @@ def test_vstack(self): assert n_vstack.tolist() == a_vstack.to_list() - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) def test_delete(self): a = ak.randint(0, 100, (10, 10)) n = a.to_ndarray() diff --git a/tests/conftest.py b/tests/conftest.py index 816cfebdd8..4857bfce1d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,10 +1,11 @@ -import subprocess import importlib import os - +import subprocess +from typing import Iterable import pytest -from arkouda import get_max_array_rank, get_config +from arkouda import get_config, get_max_array_rank +from arkouda.client import get_array_ranks from server_util.test.server_test_util import ( is_multilocale_arkouda, # TODO probably not needed ) @@ -131,6 +132,24 @@ def skip_by_rank(request): if request.node.get_closest_marker("skip_if_max_rank_greater_than").args[0] < pytest.max_rank: pytest.skip("this test requires server with max_array_dims =< {}".format(pytest.max_rank)) + if request.node.get_closest_marker("skip_if_rank_not_compiled"): + ranks_requested = request.node.get_closest_marker("skip_if_rank_not_compiled").args[0] + array_ranks = get_array_ranks() + if isinstance(ranks_requested, int): + if ranks_requested not in array_ranks: + pytest.skip("this test requires server compiled with rank {}".format(array_ranks)) + elif isinstance(ranks_requested, Iterable): + for i in ranks_requested: + if isinstance(i, int): + if i not in array_ranks: + pytest.skip( + "this test requires server compiled with rank(s) {}".format(array_ranks) + ) + else: + raise TypeError("skip_if_rank_not_compiled only accepts type int or list of int.") + else: + raise TypeError("skip_if_rank_not_compiled only accepts type int or list of int.") + @pytest.fixture(autouse=True) def skip_by_num_locales(request): diff --git a/tests/numpy/manipulation_functions_test.py b/tests/numpy/manipulation_functions_test.py index fb8e7d1272..5238c93353 100644 --- a/tests/numpy/manipulation_functions_test.py +++ b/tests/numpy/manipulation_functions_test.py @@ -19,7 +19,7 @@ def test_flip_pdarray(self, size, dtype): f = ak.flip(a) assert_equal(f, a[::-1]) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) @pytest.mark.parametrize("size", pytest.prob_size) @pytest.mark.parametrize("dtype", [ak.int64, ak.uint64, ak.float64]) def test_flip_multi_dim(self, size, dtype): @@ -27,7 +27,7 @@ def test_flip_multi_dim(self, size, dtype): f = ak.flip(a) assert_equal(f, (size * 4 - 1) - a) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("size", pytest.prob_size) def test_flip_multi_dim_bool(self, size): shape = (size, 2) @@ -69,7 +69,7 @@ def test_squeeze_1D(self, size, dtype): z = ak.array([1]) assert_equal(ak.squeeze(z), ak.array([1])) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) @pytest.mark.parametrize("size", pytest.prob_size) @pytest.mark.parametrize("dtype", DTYPES) def test_squeeze(self, size, dtype): diff --git a/tests/numpy/numeric_test.py b/tests/numpy/numeric_test.py index a1d4359820..ccb296ae27 100644 --- a/tests/numpy/numeric_test.py +++ b/tests/numpy/numeric_test.py @@ -312,7 +312,7 @@ def test_histogram(self, num_type): # log and exp tests were identical, and so have been combined. @pytest.mark.skipif(pytest.host == "horizon", reason="Fails on horizon") - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) @pytest.mark.parametrize("num_type1", NO_BOOL) @pytest.mark.parametrize("num_type2", NO_BOOL) def test_histogram_multidim(self, num_type1, num_type2): @@ -591,7 +591,8 @@ def test_isinf_isfinite(self, prob_size): """ Test isinf and isfinite. These return pdarrays of T/F values as appropriate. """ - def isinf_isfin_check(nda, pda) : + + def isinf_isfin_check(nda, pda): warnings.filterwarnings("ignore") nda_blowup = np.exp(nda) warnings.filterwarnings("default") @@ -599,12 +600,12 @@ def isinf_isfin_check(nda, pda) : assert (np.isinf(nda_blowup) == ak.isinf(pda_blowup).to_ndarray()).all() assert (np.isfinite(nda_blowup) == ak.isfinite(pda_blowup).to_ndarray()).all() - def derive_multi_shape(r) : + def derive_multi_shape(r): i = 1 - while i**r < prob_size : + while i**r < prob_size: i += 1 - i = i if i**r <= prob_size else i-1 - return i**r, r*[i] + i = i if i**r <= prob_size else i - 1 + return i**r, r * [i] # first the 1D case, then the max rank case @@ -619,7 +620,7 @@ def derive_multi_shape(r) : # only the max rank case is done, because only rank 1 and max_array_rank are # guaranteed to be covered by the arkouda interface. In-between ranks may not be. - newsize, newshape = derive_multi_shape (get_max_array_rank()) + newsize, newshape = derive_multi_shape(get_max_array_rank()) nda = nda[0:newsize].reshape(newshape) pda = ak.array(nda) isinf_isfin_check(nda, pda) @@ -931,7 +932,7 @@ def test_putmask(self, prob_size): # the resulting matrices are on the order of size*size. # tril works on ints, floats, or bool - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled(2) @pytest.mark.parametrize("data_type", INT_FLOAT_BOOL) @pytest.mark.parametrize("prob_size", pytest.prob_size) def test_tril(self, data_type, prob_size): @@ -959,7 +960,7 @@ def test_tril(self, data_type, prob_size): @pytest.mark.parametrize("data_type", INT_FLOAT_BOOL) @pytest.mark.parametrize("prob_size", pytest.prob_size) - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) def test_triu(self, data_type, prob_size): size = int(sqrt(prob_size)) @@ -982,7 +983,7 @@ def test_triu(self, data_type, prob_size): # transpose works on ints, floats, or bool - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("data_type", INT_FLOAT_BOOL) @pytest.mark.parametrize("prob_size", pytest.prob_size) def test_transpose(self, data_type, prob_size): @@ -1005,7 +1006,7 @@ def test_transpose(self, data_type, prob_size): assert check(npa, ppa, data_type) # eye works on ints, floats, or bool - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("data_type", INT_FLOAT_BOOL) @pytest.mark.parametrize("prob_size", pytest.prob_size) def test_eye(self, data_type, prob_size): @@ -1028,7 +1029,7 @@ def test_eye(self, data_type, prob_size): assert check(nda, pda, data_type) # matmul works on ints, floats, or bool - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("data_type1", INT_FLOAT_BOOL) @pytest.mark.parametrize("data_type2", INT_FLOAT_BOOL) @pytest.mark.parametrize("prob_size", pytest.prob_size) @@ -1056,7 +1057,7 @@ def test_matmul(self, data_type1, data_type2, prob_size): # vecdot works on ints, floats, or bool, with the limitation that both inputs can't # be bool - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("data_type1", INT_FLOAT_BOOL) @pytest.mark.parametrize("data_type2", INT_FLOAT) @pytest.mark.parametrize("prob_size", pytest.prob_size) diff --git a/tests/numpy/utils_test.py b/tests/numpy/utils_test.py index b10599022e..414a0c5a1a 100644 --- a/tests/numpy/utils_test.py +++ b/tests/numpy/utils_test.py @@ -18,6 +18,6 @@ def test_shape_strings(self): a = ak.array(["a", "b", "c"]) assert ak.shape(a) == np.shape(a.to_ndarray()) - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) def test_shape_multidim_pdarray(self): assert ak.shape(ak.eye(3, 2)) == (3, 2) diff --git a/tests/pdarray_creation_test.py b/tests/pdarray_creation_test.py index f3878eb069..9794c0213b 100644 --- a/tests/pdarray_creation_test.py +++ b/tests/pdarray_creation_test.py @@ -43,7 +43,7 @@ def test_array_creation(self, dtype): assert len(pda) == fixed_size assert dtype == pda.dtype - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) @pytest.mark.parametrize("size", pytest.prob_size) @pytest.mark.parametrize("dtype", [int, ak.int64, ak.uint64, float, ak.float64, bool, ak.bool_]) def test_array_creation_multi_dim(self, size, dtype): @@ -91,7 +91,7 @@ def test_large_array_creation(self, size): assert isinstance(pda, ak.pdarray if pda.dtype != str else ak.Strings) assert len(pda) == size - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) def test_array_creation_misc(self): av = ak.array(np.array([[0, 1], [0, 1]])) assert isinstance(av, ak.pdarray) @@ -105,7 +105,7 @@ def test_array_creation_misc(self): with pytest.raises(TypeError): ak.array(list(list(0))) - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) def test_array_creation_transpose_bug_reproducer(self): import numpy as np @@ -364,13 +364,13 @@ def test_zeros_dtype(self, size, dtype): assert dtype == zeros.dtype assert (0 == zeros).all() - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("dtype", [int, ak.int64, float, ak.float64, bool, ak.bool_]) @pytest.mark.parametrize("shape", [0, 2, (2, 3)]) def test_ones_match_numpy(self, shape, dtype): assert_equivalent(ak.zeros(shape, dtype=dtype), np.zeros(shape, dtype=dtype)) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) @pytest.mark.parametrize("size", pytest.prob_size) @pytest.mark.parametrize("dtype", [ak.int64, float, ak.float64, bool, ak.bool_, ak.bigint]) def test_zeros_dtype_mult_dim(self, size, dtype): @@ -411,7 +411,7 @@ def test_ones_dtype(self, size, dtype): assert dtype == ones.dtype assert (1 == ones).all() - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("dtype", [int, ak.int64, float, ak.float64, bool, ak.bool_]) @pytest.mark.parametrize("shape", [0, 2, (2, 3)]) def test_ones_match_numpy(self, shape, dtype): @@ -419,7 +419,7 @@ def test_ones_match_numpy(self, shape, dtype): @pytest.mark.parametrize("dtype", [int, ak.int64, float, ak.float64, bool, ak.bool_, ak.bigint]) @pytest.mark.parametrize("size", pytest.prob_size) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) def test_ones_dtype_multi_dim(self, size, dtype): shape = (2, 2, size) ones = ak.ones(shape, dtype) @@ -468,7 +468,7 @@ def test_full_dtype(self, size, dtype): assert dtype == type_full.dtype assert (1 == type_full).all() - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("dtype", [int, ak.int64, float, ak.float64, bool, ak.bool_]) @pytest.mark.parametrize("shape", [0, 2, (2, 3)]) def test_full_match_numpy(self, shape, dtype): @@ -476,7 +476,7 @@ def test_full_match_numpy(self, shape, dtype): ak.full(shape, fill_value=2, dtype=dtype), np.full(shape, fill_value=2, dtype=dtype) ) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) @pytest.mark.parametrize("size", pytest.prob_size) @pytest.mark.parametrize("dtype", [int, ak.int64, ak.uint64, float, ak.float64, bool, ak.bool_]) def test_full_dtype_multi_dim(self, size, dtype): @@ -753,7 +753,7 @@ def test_random_strings_lognormal_with_seed(self): ) assert printable_randoms == pda.to_list() - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2]) def test_mulitdimensional_array_creation(self): a = ak.array([[0, 0], [0, 1], [1, 1]]) assert isinstance(a, ak.pdarray) diff --git a/tests/pdarrayclass_test.py b/tests/pdarrayclass_test.py index 33a4a20e97..dc4cd59ef0 100644 --- a/tests/pdarrayclass_test.py +++ b/tests/pdarrayclass_test.py @@ -22,7 +22,7 @@ class TestPdarrayClass: - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("dtype", DTYPES) def test_reshape(self, dtype): a = ak.arange(4, dtype=dtype) @@ -30,7 +30,7 @@ def test_reshape(self, dtype): assert r.shape == (2, 2) assert isinstance(r, ak.pdarray) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) def test_reshape_and_flatten_bug_reproducer(self): dtype = "bigint" size = 10 @@ -44,7 +44,7 @@ def test_shape(self, dtype): assert isinstance(a.shape, tuple) assert a.shape == np_a.shape - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("dtype", list(set(DTYPES) - set(["bool"]))) def test_shape_multidim(self, dtype): a = ak.arange(4, dtype=dtype).reshape((2, 2)) @@ -58,7 +58,7 @@ def test_flatten(self, size, dtype): a = ak.arange(size, dtype=dtype) ak_assert_equal(a.flatten(), a) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) @pytest.mark.parametrize("dtype", DTYPES) @pytest.mark.parametrize("size", pytest.prob_size) def test_flatten(self, size, dtype): @@ -81,7 +81,7 @@ def test_is_sorted(self, size, dtype, axis): c = ak.randint(0, size // 10, size, seed=SEED) assert not ak.is_sorted(c, axis=axis) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) @pytest.mark.parametrize("dtype", list(set(DTYPES) - set(["bool"]))) @pytest.mark.parametrize("axis", [None, 0, 1, (0, 2), (0, 1, 2)]) def test_is_sorted_multidim(self, dtype, axis): @@ -126,7 +126,7 @@ def test_is_locally_sorted_multi_locale(self, size, dtype): assert is_locally_sorted(a) assert not is_sorted(a) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) @pytest.mark.skip_if_nl_greater_than(2) @pytest.mark.parametrize("dtype", DTYPES) @pytest.mark.parametrize("axis", [None, 0, 1, (0, 2), (0, 1, 2)]) @@ -171,7 +171,7 @@ def test_index_reduction_1D(self, op, dtype, arry_gen, size, axis): ak_result = ak_op(pda, axis=axis) ak_assert_equivalent(ak_result, np_op(nda, axis=axis)) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) @pytest.mark.parametrize("op", INDEX_REDUCTION_OPS) @pytest.mark.parametrize("size", pytest.prob_size) @pytest.mark.parametrize("dtype", DTYPES) @@ -196,7 +196,7 @@ def test_reductions_match_numpy_1D(self, op, size, dtype, arry_gen, axis): pda = arry_gen(size, dtype=dtype) self.assert_reduction_ops_match(op, pda, axis=axis) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) @pytest.mark.parametrize("op", REDUCTION_OPS) @pytest.mark.parametrize("size", pytest.prob_size) @pytest.mark.parametrize("dtype", DTYPES) @@ -213,7 +213,7 @@ def test_reductions_match_numpy_1D_TF(self, op, axis): pda = ak.array([True, True, False, True, True, True, True, True]) self.assert_reduction_ops_match(op, pda, axis=axis) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([2, 3]) @pytest.mark.parametrize("op", REDUCTION_OPS) @pytest.mark.parametrize("axis", [None, 0, 1, (0, 2), (0, 1, 2)]) def test_reductions_match_numpy_3D_TF(self, op, axis): diff --git a/tests/testing/asserters_test.py b/tests/testing/asserters_test.py index 892d78163b..58b8234c8f 100644 --- a/tests/testing/asserters_test.py +++ b/tests/testing/asserters_test.py @@ -170,7 +170,7 @@ def test_assert_almost_equal(self, size, left_as_arkouda, right_as_arkouda): with pytest.raises(AssertionError): assert_almost_equivalent(convert_left(df), convert_right(df3), atol=atol, rtol=rtol) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) @pytest.mark.parametrize("size", pytest.prob_size) @pytest.mark.parametrize("left_as_arkouda", [True, False]) @pytest.mark.parametrize("right_as_arkouda", [True, False]) @@ -957,7 +957,7 @@ def test_assert_equal(self, size, left_as_arkouda, right_as_arkouda): with pytest.raises(AssertionError): assert_equivalent(convert_left(df), convert_right(df2)) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) @pytest.mark.parametrize("size", pytest.prob_size) @pytest.mark.parametrize("left_as_arkouda", [True, False]) @pytest.mark.parametrize("right_as_arkouda", [True, False]) @@ -1076,7 +1076,7 @@ def test_assert_arkouda_array_equal(self, size, left_as_arkouda, right_as_arkoud with pytest.raises(AssertionError): assert_arkouda_array_equivalent(convert_left(s), convert_right(c)) - @pytest.mark.skip_if_max_rank_less_than(3) + @pytest.mark.skip_if_rank_not_compiled([3]) @pytest.mark.parametrize("size", pytest.prob_size) @pytest.mark.parametrize("left_as_arkouda", [True, False]) @pytest.mark.parametrize("right_as_arkouda", [True, False]) @@ -1097,7 +1097,7 @@ def test_assert_arkouda_array_equal_multi_dim(self, size, left_as_arkouda, right with pytest.raises(AssertionError): assert_arkouda_array_equivalent(convert_left(a), convert_right(a2)) - @pytest.mark.skip_if_max_rank_less_than(2) + @pytest.mark.skip_if_rank_not_compiled([2]) @pytest.mark.parametrize("left_as_arkouda", [True, False]) @pytest.mark.parametrize("right_as_arkouda", [True, False]) def test_assert_arkouda_array_equal_shape(self, left_as_arkouda, right_as_arkouda):