From 5016b59fd966c32091687592bde9e7f085957f5b Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Thu, 25 Aug 2022 17:38:35 -0500 Subject: [PATCH] fix: Use dtype=np.int64, not int, for platform independence (Windows). --- tests/v2/test_0008-slices-and-getitem.py | 10 ++++----- tests/v2/test_0021-emptyarray.py | 28 ++++++++++++------------ tests/v2/test_0024-use-regular-array.py | 26 ++++++++++++---------- tests/v2/test_1473-from-rdataframe.py | 2 +- 4 files changed, 35 insertions(+), 31 deletions(-) diff --git a/tests/v2/test_0008-slices-and-getitem.py b/tests/v2/test_0008-slices-and-getitem.py index 1c9a80e9c7..11cff7d4c3 100644 --- a/tests/v2/test_0008-slices-and-getitem.py +++ b/tests/v2/test_0008-slices-and-getitem.py @@ -67,7 +67,7 @@ def test_numpyarray_getitem_next(): c = np.array([False, False, False, True, True, True, False, True, False, True]) assert to_list(b[c]) == to_list(a[c]) assert b.typetracer[c].form == b[c].form - c = np.array([], dtype=int) + c = np.array([], dtype=np.int64) assert to_list(b[c]) == to_list(a[c]) assert b.typetracer[c].form == b[c].form @@ -80,7 +80,7 @@ def test_numpyarray_getitem_next(): c = np.array([False, False, False, True, True, True, False, True, False, True]) assert to_list(b[c]) == to_list(a[c]) assert b.typetracer[c].form == b[c].form - c = np.array([], dtype=int) + c = np.array([], dtype=np.int64) assert to_list(b[c]) == to_list(a[c]) assert b.typetracer[c].form == b[c].form @@ -105,10 +105,10 @@ def test_numpyarray_getitem_next(): assert to_list(b[c]) == to_list(a[c]) assert b.typetracer[c].form == b[c].form - c = np.array([], dtype=int) + c = np.array([], dtype=np.int64) assert to_list(b[c]) == to_list(a[c]) - c1 = np.array([], dtype=int) - c2 = np.array([], dtype=int) + c1 = np.array([], dtype=np.int64) + c2 = np.array([], dtype=np.int64) assert to_list(b[c1, c2]) == to_list(a[c1, c2]) assert b.typetracer[c1, c2].form == b[c1, c2].form diff --git a/tests/v2/test_0021-emptyarray.py b/tests/v2/test_0021-emptyarray.py index 5caae1289e..e4186c7b55 100644 --- a/tests/v2/test_0021-emptyarray.py +++ b/tests/v2/test_0021-emptyarray.py @@ -75,27 +75,27 @@ def test_getitem(): assert a.typetracer[2, 1][100:200].form == a[2, 1][100:200].form assert to_list(a[2, 1, 100:200]) == [] assert a.typetracer[2, 1, 100:200].form == a[2, 1, 100:200].form - assert to_list(a[2, 1][np.array([], dtype=int)]) == [] + assert to_list(a[2, 1][np.array([], dtype=np.int64)]) == [] assert ( - a.typetracer[2, 1][np.array([], dtype=int)].form - == a[2, 1][np.array([], dtype=int)].form + a.typetracer[2, 1][np.array([], dtype=np.int64)].form + == a[2, 1][np.array([], dtype=np.int64)].form ) - assert to_list(a[2, 1, np.array([], dtype=int)]) == [] + assert to_list(a[2, 1, np.array([], dtype=np.int64)]) == [] assert ( - a.typetracer[2, 1, np.array([], dtype=int)].form - == a[2, 1, np.array([], dtype=int)].form + a.typetracer[2, 1, np.array([], dtype=np.int64)].form + == a[2, 1, np.array([], dtype=np.int64)].form ) with pytest.raises(IndexError): - a[2, 1, np.array([0], dtype=int)] + a[2, 1, np.array([0], dtype=np.int64)] with pytest.raises(IndexError): a[2, 1][100:200, 0] with pytest.raises(IndexError): a[2, 1][100:200, 200:300] - assert to_list(a[2, 1][100:200, np.array([], dtype=int)]) == [] + assert to_list(a[2, 1][100:200, np.array([], dtype=np.int64)]) == [] assert ( - a.typetracer[2, 1][100:200, np.array([], dtype=int)].form - == a[2, 1][100:200, np.array([], dtype=int)].form + a.typetracer[2, 1][100:200, np.array([], dtype=np.int64)].form + == a[2, 1][100:200, np.array([], dtype=np.int64)].form ) assert to_list(a[1:, 1:]) == [[[]], [[], []]] @@ -159,10 +159,10 @@ def test_from_json_getitem(): ) assert a[2, 1][100:200].tolist() == [] assert a[2, 1, 100:200].tolist() == [] - assert a[2, 1][np.array([], dtype=int)].tolist() == [] - assert a[2, 1, np.array([], dtype=int)].tolist() == [] + assert a[2, 1][np.array([], dtype=np.int64)].tolist() == [] + assert a[2, 1, np.array([], dtype=np.int64)].tolist() == [] with pytest.raises(IndexError) as excinfo: - a[2, 1, np.array([0], dtype=int)] + a[2, 1, np.array([0], dtype=np.int64)] assert "index out of range while attempting to get index 0" in str(excinfo.value) with pytest.raises(IndexError) as excinfo: a[2, 1][100:200, 0] @@ -179,7 +179,7 @@ def test_from_json_getitem(): # FIXME: Failed: DID NOT RAISE # with pytest.raises(IndexError) as excinfo: - # a[2, 1][100:200, np.array([], dtype=int)] + # a[2, 1][100:200, np.array([], dtype=np.int64)] # assert ", too many dimensions in slice" in str(excinfo.value) assert a[1:, 1:].tolist() == [[[]], [[], []]] diff --git a/tests/v2/test_0024-use-regular-array.py b/tests/v2/test_0024-use-regular-array.py index 77d6f2cc0c..76df62adc2 100644 --- a/tests/v2/test_0024-use-regular-array.py +++ b/tests/v2/test_0024-use-regular-array.py @@ -10,20 +10,24 @@ def test_empty_array_slice(): # inspired by PR021::test_getitem a = ak._v2.operations.from_json("[[], [[], []], [[], [], []]]") - assert to_list(a[2, 1, np.array([], dtype=int)]) == [] + assert to_list(a[2, 1, np.array([], dtype=np.int64)]) == [] # FIXME: assert [[]] == [] - # assert to_list(a[2, np.array([1], dtype=int), np.array([], dtype=int)]) == [] + # assert to_list(a[2, np.array([1], dtype=np.int64), np.array([], dtype=np.int64)]) == [] a = ak._v2.operations.from_iter([[], [[], []], [[], [], []]], highlevel=False) - assert to_list(a[2, 1, np.array([], dtype=int)]) == [] + assert to_list(a[2, 1, np.array([], dtype=np.int64)]) == [] assert ( - a.typetracer[2, 1, np.array([], dtype=int)].form - == a[2, 1, np.array([], dtype=int)].form + a.typetracer[2, 1, np.array([], dtype=np.int64)].form + == a[2, 1, np.array([], dtype=np.int64)].form ) - assert to_list(a[2, np.array([1], dtype=int), np.array([], dtype=int)]) == [[]] + assert to_list( + a[2, np.array([1], dtype=np.int64), np.array([], dtype=np.int64)] + ) == [[]] assert ( - a.typetracer[2, np.array([1], dtype=int), np.array([], dtype=int)].form - == a[2, np.array([1], dtype=int), np.array([], dtype=int)].form + a.typetracer[ + 2, np.array([1], dtype=np.int64), np.array([], dtype=np.int64) + ].form + == a[2, np.array([1], dtype=np.int64), np.array([], dtype=np.int64)].form ) # inspired by PR015::test_deep_numpy @@ -45,10 +49,10 @@ def test_empty_array_slice(): listarray.typetracer[[2, 0, 0, -1], [1, -1, 0, 0], [0, 1, 0, 1]].form == listarray[[2, 0, 0, -1], [1, -1, 0, 0], [0, 1, 0, 1]].form ) - assert to_list(listarray[2, 1, np.array([], dtype=int)]) == [] + assert to_list(listarray[2, 1, np.array([], dtype=np.int64)]) == [] assert ( - listarray.typetracer[2, 1, np.array([], dtype=int)].form - == listarray[2, 1, np.array([], dtype=int)].form + listarray.typetracer[2, 1, np.array([], dtype=np.int64)].form + == listarray[2, 1, np.array([], dtype=np.int64)].form ) assert to_list(listarray[2, 1, []]) == [] assert listarray.typetracer[2, 1, []].form == listarray[2, 1, []].form diff --git a/tests/v2/test_1473-from-rdataframe.py b/tests/v2/test_1473-from-rdataframe.py index 18f0b69f5f..9df4bc5638 100644 --- a/tests/v2/test_1473-from-rdataframe.py +++ b/tests/v2/test_1473-from-rdataframe.py @@ -20,7 +20,7 @@ def test_to_from_data_frame_large(): rows = 3 ** (n // 2) cols = n - arr = np.zeros((rows, cols), dtype=int) + arr = np.zeros((rows, cols), dtype=np.int64) shape = (rows,) source = np.array([-1, 0, 1], dtype=np.int64)[:, None]