-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[Datasets] Fix ndarray representation of single-element ragged tensor slices. #30514
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,7 +178,14 @@ def test_arrow_variable_shaped_tensor_array_slice(): | |
slice(0, 3), | ||
] | ||
for slice_ in slices: | ||
for o, e in zip(ata[slice_], arr[slice_]): | ||
ata_slice = ata[slice_] | ||
ata_slice_np = ata_slice.to_numpy() | ||
arr_slice = arr[slice_] | ||
# Check for equivalent dtypes and shapes. | ||
assert ata_slice_np.dtype == arr_slice.dtype | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why doesn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both the data type and element shape are exposed on the underlying tensor array type, i.e. We haven't exposed them directly on Agreed that making the Arrow-side extension type more user-friendly is worth doing though, we should open a ticket for that. |
||
assert ata_slice_np.shape == arr_slice.shape | ||
# Iteration over tensor array slices triggers NumPy conversion. | ||
for o, e in zip(ata_slice, arr_slice): | ||
np.testing.assert_array_equal(o, e) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we converting to NumPy here so we can get the
dtype
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to using NumPy as the "source of truth" for slicing semantics for multi-dimensional arrays (which we typically do), we're primarily interested in whether the slicing results in the expected semantics for the NumPy views of the data rather than the Arrow data, e.g. the fact that slicing preserves the Arrow-level typing doesn't need to be tested, that's guaranteed by Arrow's extension type slicing, but we need to make sure that the NumPy-level dtype is what we'd expect.