Conversation
|
Can one of the admins verify this patch? Admins can comment |
np.array
|
As far as I can tell test failures are not related with my changes |
|
ok to test |
| def test_slicing_row_with_0d_numpy_arrays(): | ||
| a, bd1 = slice_array( | ||
| "y", | ||
| "x", | ||
| ((3, 3, 3, 2), (3, 3, 3, 1)), | ||
| (np.array(0), slice(None, None, None)), | ||
| itemsize=8, | ||
| ) | ||
|
|
||
| i = [True] + [False] * 10 | ||
| index = (i, slice(None, None, None)) | ||
| index = normalize_index(index, (11, 10)) | ||
| b, bd2 = slice_array("y", "x", ((3, 3, 3, 2), (3, 3, 3, 1)), index, itemsize=8) | ||
|
|
||
| # bd1=((3, 3, 3, 1),) | ||
| # bd2=((1,), (3, 3, 3, 1)) | ||
| assert bd1[0] == bd2[1] | ||
| for key_b, value in b.items(): | ||
| if key_b[0] == "x": | ||
| key_a = key_b | ||
| elif key_b[0] == "y": | ||
| key_a = key_b[::2] | ||
| np.testing.assert_equal(a[key_a], value) | ||
|
|
||
|
|
||
| def test_slicing_col_with_0d_numpy_arrays(): | ||
| a, bd1 = slice_array( | ||
| "y", | ||
| "x", | ||
| ((3, 3, 3, 1), (3, 3, 3, 2)), | ||
| (slice(None, None, None), np.array(0)), | ||
| itemsize=8, | ||
| ) | ||
|
|
||
| i = [True] + [False] * 10 | ||
| index = (slice(None, None, None), i) | ||
| index = normalize_index(index, (10, 11)) | ||
| b, bd2 = slice_array("y", "x", ((3, 3, 3, 1), (3, 3, 3, 2)), index, itemsize=8) | ||
|
|
||
| # bd1=((3, 3, 3, 1),) | ||
| # bd2=((3, 3, 3, 1), (1,)) | ||
| assert bd1[0] == bd2[0] | ||
| for key_b, value in b.items(): | ||
| if key_b[0] == "x": | ||
| key_a = key_b | ||
| elif key_b[0] == "y": | ||
| key_a = key_b[:2] | ||
| np.testing.assert_equal(a[key_a], value) | ||
|
|
||
|
|
There was a problem hiding this comment.
I'm curious why these tests are written this way. I think the intent of this test would be more clear if we used simple user-facing APIs. For example, using the problematic snippet provided in the original issue, something like
def test_slicing_with_0d_numpy_arrays():
x = da.arange(10, chunks=2)
x_np = np.arange(10)
actual = x[np.array(0)]
expected = x_np[np.array(0)]
assert_eq(actual, expected)Should, I think, test what we're after with the changes in this PR. @fAndreuzzi thoughts?
There was a problem hiding this comment.
To be honest I've simply tried to mimic some of the tests I found in test_slicing.py, I think they test that chunks are not cut in weird ways after slicing. But I know very little of the codebase, so I can for sure change the tests to what you suggested @jrbourbeau
pre-commit run --all-files