Skip to content

Commit

Permalink
Closes Bears-R-Us#3415: Update compare_test (Bears-R-Us#3686)
Browse files Browse the repository at this point in the history
Co-authored-by: Amanda Potts <ajpotts@users.noreply.github.com>
  • Loading branch information
ajpotts and ajpotts authored Aug 22, 2024
1 parent 03cfc70 commit 3d65f85
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 180 deletions.
1 change: 0 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ testpaths =
tests/client_dtypes_test.py
tests/client_test.py
tests/coargsort_test.py
tests/compare_test.py
tests/dataframe_test.py
tests/datetime_test.py
tests/extrema_test.py
Expand Down
179 changes: 0 additions & 179 deletions tests/compare_test.py

This file was deleted.

122 changes: 122 additions & 0 deletions tests/indexing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,125 @@ def test_handling_bigint_max_bits(self):
a = ak.arange(2**200 - 1, 2**200 + 11, max_bits=3)
a[:] = ak.arange(2**200 - 1, 2**200 + 11)
assert [7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2] == a.to_list()

@pytest.mark.parametrize("size", pytest.prob_size)
def test_compare_get_slice(self, size):
# create np version
a = np.arange(size)
a = a[::2]
# create ak version
b = ak.arange(size)
b = b[::2]
assert np.allclose(a, b.to_ndarray())

@pytest.mark.parametrize("size", pytest.prob_size)
def test_compare_set_slice_value(self, size):
# create np version
a = np.ones(size)
a[::2] = -1
# create ak version
b = ak.ones(size)
b[::2] = -1
assert np.allclose(a, b.to_ndarray())

@pytest.mark.parametrize("size", pytest.prob_size)
def test_compare_set_slice(self, size):
# create np version
a = np.ones(size)
a[::2] = a[::2] * -1
# create ak version
b = ak.ones(size)
b[::2] = b[::2] * -1
assert np.allclose(a, b.to_ndarray())

@pytest.mark.parametrize("size", pytest.prob_size)
def test_compare_get_bool_iv(self, size):
# create np version
a = np.arange(size)
a = a[a < size // 2]
# create ak version
b = ak.arange(size)
b = b[b < size // 2]
assert np.allclose(a, b.to_ndarray())

@pytest.mark.parametrize("size", pytest.prob_size)
def test_compare_set_bool_iv_value(self, size):
# create np version
a = np.arange(size)
a[a < size // 2] = -1
# create ak version
b = ak.arange(size)
b[b < size // 2] = -1
assert np.allclose(a, b.to_ndarray())

@pytest.mark.parametrize("size", pytest.prob_size)
def check_set_bool_iv(self, size):
# create np version
a = np.arange(size)
a[a < size // 2] = a[: size // 2] * -1
# create ak version
b = ak.arange(size)
b[b < size // 2] = b[: size // 2] * -1
assert np.allclose(a, b.to_ndarray())

@pytest.mark.parametrize("size", pytest.prob_size)
def check_get_integer_iv(self, size):
# create np version
a = np.arange(size)
iv = np.arange(size // 2)
a = a[iv]
# create ak version
b = ak.arange(size)
iv = ak.arange(size // 2)
b = b[iv]
assert np.allclose(a, b.to_ndarray())

@pytest.mark.parametrize("size", pytest.prob_size)
def test_compare_set_integer_iv_val(self, size):
# create np version
a = np.arange(size)
iv = np.arange(size // 2)
a[iv] = -1
# create ak version
b = ak.arange(size)
iv = ak.arange(size // 2)
b[iv] = -1
assert np.allclose(a, b.to_ndarray())

@pytest.mark.parametrize("size", pytest.prob_size)
def test_compare_set_integer_iv(self, size):
# create np version
a = np.arange(size)
iv = np.arange(size // 2)
a[iv] = iv * 10
# create ak version
b = ak.arange(size)
iv = ak.arange(size // 2)
b[iv] = iv * 10
assert np.allclose(a, b.to_ndarray())

@pytest.mark.parametrize("size", pytest.prob_size)
def test_compare_get_integer_idx(self, size):
# create np version
a = np.arange(size)
v1 = a[size // 2]
# create ak version
b = ak.arange(size)
v2 = b[size // 2]
assert v1 == v2
assert a[-1] == b[-1]

@pytest.mark.parametrize("size", pytest.prob_size)
def test_compare_set_integer_idx(self, size):
# create np version
a = np.arange(size)
a[size // 2] = -1
a[-1] = -1
v1 = a[size // 2]
# create ak version
b = ak.arange(size)
b[size // 2] = -1
b[-1] = -1
v2 = b[size // 2]
assert v1 == v2
assert a[-1] == b[-1]
21 changes: 21 additions & 0 deletions tests/pdarray_creation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ def test_arange_misc(self):
int_array = ak.arange(1, 1000, 1)
assert (uint_array == int_array).all()

@pytest.mark.parametrize("size", pytest.prob_size)
@pytest.mark.parametrize("dtype", [ak.float64, ak.uint64, ak.float64])
@pytest.mark.parametrize("start", [0, 2, 5])
@pytest.mark.parametrize("stride", [1, 3])
def test_compare_arange(self, size, dtype, start, stride):
# create np version
nArange = np.arange(start, size, stride, dtype=dtype)
# create ak version
aArange = ak.arange(start, size, stride, dtype=dtype)
assert np.allclose(nArange, aArange.to_ndarray())

@pytest.mark.parametrize("size", pytest.prob_size)
@pytest.mark.parametrize("array_type", [ak.int64, ak.float64, bool])
def test_randint_array_dtype(self, size, array_type):
Expand Down Expand Up @@ -451,6 +462,16 @@ def test_linspace(self):
]:
assert (int_arr == ak.linspace(*args)).all()

@pytest.mark.parametrize("start", [0, 0.5, 2])
@pytest.mark.parametrize("stop", [50, 101])
@pytest.mark.parametrize("size", pytest.prob_size)
def test_compare_linspace(self, size, start, stop):
# create np version
a = np.linspace(start, stop, size)
# create ak version
b = ak.linspace(start, stop, size)
assert np.allclose(a, b.to_ndarray())

@pytest.mark.parametrize("size", pytest.prob_size)
@pytest.mark.parametrize("dtype", INT_SCALARS)
def test_standard_normal(self, size, dtype):
Expand Down
29 changes: 29 additions & 0 deletions tests/sort_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,35 @@ def np_is_sorted(arr):


class TestSort:

@pytest.mark.parametrize("size", pytest.prob_size)
@pytest.mark.parametrize("dtype", [ak.float64, ak.uint64, ak.float64])
def test_compare_argsort(self, size, dtype):
# create np version
a = np.arange(size, dtype=dtype)
a = a[::-1]
iv = np.argsort(a)
a = a[iv]
# create ak version
b = ak.arange(size, dtype=dtype)
b = b[::-1]
iv = ak.argsort(b)
b = b[iv]
assert np.array_equal(a, b.to_ndarray())

@pytest.mark.parametrize("size", pytest.prob_size)
@pytest.mark.parametrize("dtype", [ak.float64, ak.uint64, ak.float64])
def test_compare_sort(self, size, dtype):
# create np version
a = np.arange(size, dtype=dtype)
a = a[::-1]
a = np.sort(a)
# create ak version
b = ak.arange(size, dtype=dtype)
b = b[::-1]
b = ak.sort(b)
assert np.allclose(a, b.to_ndarray())

@pytest.mark.parametrize("dtype", NUMERIC_AND_BIGINT_TYPES)
def test_is_sorted(self, dtype):
pda = make_ak_arrays(dtype)
Expand Down

0 comments on commit 3d65f85

Please sign in to comment.