8000 [WIP [ENH] metadata attribute for Annotations by eioe · Pull Request #12213 · mne-tools/mne-python · GitHub
[go: up one dir, main page]

Skip to content

[WIP [ENH] metadata attribute for Annotations #12213

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

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 15, 2023
commit becf06008a5a259e351d65c83700ce41d28e7e49
27 changes: 16 additions & 11 deletions mne/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@ def _check_o_d_s_c(onset, duration, description, ch_names, metadata):
_validate_type(md, dict, f"metadata[{ai}]")
metadata = np.array(metadata, dtype=object)

if not (len(onset) == len(duration) == len(description) ==
len(ch_names) == len(metadata)):
if not (
len(onset)
== len(duration)
== len(description)
== len(ch_names)
== len(metadata)
):
raise ValueError(
"Onset, duration, description, ch_names, and metadata must be "
f"equal in sizes, got {len(onset)}, {len(duration)}, "
Expand Down Expand Up @@ -286,8 +291,7 @@ class Annotations:
""" # noqa: E501

def __init__(
self, onset, duration, description, orig_time=None, ch_names=None,
metadata=None
self, onset, duration, description, orig_time=None, ch_names=None, metadata=None
): # noqa: D102
self._orig_time = _handle_meas_date(orig_time)
self.onset, self.duration, self.description, self.ch_names,
Expand Down Expand Up @@ -358,8 +362,11 @@ def __iadd__(self, other):
"(got %s != %s)" % (self.orig_time, other.orig_time)
)
return self.append(
other.onset, other.duration, other.description, other.ch_names,
other._metadata
other.onset,
other.duration,
other.description,
other.ch_names,
other._metadata,
)

def __iter__(self):
Expand All @@ -373,8 +380,7 @@ def __iter__(self):
def __getitem__(self, key, *, with_ch_names=None):
"""Propagate indexing and slicing to the underlying numpy structure."""
if isinstance(key, int_like):
out_keys = ("onset", "duration", "description", "orig_time",
"metadata")
out_keys = ("onset", "duration", "description", "orig_time", "metadata")
out_vals = (
self.onset[key],
self.duration[key],
Expand All @@ -398,8 +404,7 @@ def __getitem__(self, key, *, with_ch_names=None):
)

@fill_doc
def append(self, onset, duration, description, ch_names=None,
metadata=None):
def append(self, onset, duration, description, ch_names=None, metadata=None):
"""Add an annotated segment. Operates inplace.

Parameters
Expand All @@ -416,7 +421,7 @@ def append(self, onset, duration, description, ch_names=None,
metadata : dict | array-like
Metadata for the annotation. Can be a dict or an array-like
object of dicts. If an array-like object, must be the same length
as ``onset``.
as ``onset``.

.. versionadded:: 0.23

Expand Down
0