Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/nexusformat/nexus/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -8113,7 +8113,9 @@ def is_real_slice(idx):
"""True if the slice contains real values."""

def is_real(x):
if isinstance(x, slice):
if x is None or x is Ellipsis:
return False
elif isinstance(x, slice):
x = [x if x is not None else 0 for x in [x.start, x.stop, x.step]]
x = np.array(x)
return not (np.issubdtype(x.dtype, np.integer) or x.dtype == bool)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ def test_field_slice(arr, idx, request):
assert field[idx].shape == arr[idx].shape


@pytest.mark.parametrize(
"arr,idx", [("arr2D", np.s_[..., -1]),
("arr2D", np.s_[0, ...]),
("arr2D", np.s_[None, 0]),
("arr3D", np.s_[1, ..., 2:4]),
("arr3D", np.s_[:, np.newaxis, 0])])
def test_field_ellipsis_and_newaxis_slice(arr, idx, request):

arr = request.getfixturevalue(arr)
field = NXfield(arr)

assert np.array_equal(field[idx].nxvalue, arr[idx])
assert field[idx].shape == arr[idx].shape


def test_field_index(arr1D):

field = NXfield(2*arr1D)
Expand Down