Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use dtype=np.int64, not int, for platform independence (Windows). #1636

Merged
merged 1 commit into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions tests/v2/test_0008-slices-and-getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
28 changes: 14 additions & 14 deletions tests/v2/test_0021-emptyarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]) == [[[]], [[], []]]
Expand Down Expand Up @@ -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]
Expand All @@ -179,7 +179,7 @@ def test_from_json_getitem():

# FIXME: Failed: DID NOT RAISE <class 'IndexError'>
# 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() == [[[]], [[], []]]
Expand Down
26 changes: 15 additions & 11 deletions tests/v2/test_0024-use-regular-array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/test_1473-from-rdataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down