Skip to content

Commit

Permalink
BUG: Fix bug with last item access (mne-tools#12248)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner authored Nov 29, 2023
1 parent 2a1f7e4 commit b107d92
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/changes/devel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Enhancements
Bugs
~~~~
- Allow :func:`mne.viz.plot_compare_evokeds` to plot eyetracking channels, and improve error handling (:gh:`12190` by `Scott Huberty`_)
- Fix bug with accessing the last data sample using ``raw[:, -1]`` where an empty array was returned (:gh:`12248` by `Eric Larson`_)
- Fix bug with type hints in :func:`mne.io.read_raw_neuralynx` (:gh:`12236` by `Richard Höchenberger`_)

API changes
Expand Down
3 changes: 3 additions & 0 deletions mne/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,9 @@ def _parse_get_set_params(self, item):
item1 = int(item1)
if isinstance(item1, (int, np.integer)):
start, stop, step = item1, item1 + 1, 1
# Need to special case -1, because -1:0 will be empty
if start == -1:
stop = None
else:
raise ValueError("Must pass int or slice to __getitem__")

Expand Down
7 changes: 7 additions & 0 deletions mne/io/tests/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,3 +1022,10 @@ def test_concatenate_raw_dev_head_t():
raw.info["dev_head_t"]["trans"][0, 0] = np.nan
raw2 = raw.copy()
concatenate_raws([raw, raw2])


def test_last_samp():
"""Test that getting the last sample works."""
raw = read_raw_fif(raw_fname).crop(0, 0.1).load_data()
last_data = raw._data[:, [-1]]
assert_array_equal(raw[:, -1][0], last_data)

0 comments on commit b107d92

Please sign in to comment.