Skip to content

Commit

Permalink
updated logical test in _chk_events (#95)
Browse files Browse the repository at this point in the history
* updated logical test in _chk_events

event["description"] can be >= 0 instead of strictly >1 for more tolerance in labeling events

* Update CITATION.cff

* Update changelog.rst

* updated docstring in _chk_events

* also fix docstr, update changelog

* fix tests

Co-authored-by: Stefan Appelhoff <[email protected]>
  • Loading branch information
compmonks and sappelhoff authored Jul 5, 2022
1 parent 1b4a89d commit 8035d9b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ authors:
- given-names: "Aniket"
family-names: "Pradhan"
orcid: https://orcid.org/0000-0002-6705-5116
- given-names: "Pierre"
family-names: "Cutellic"
orcid: "https://orcid.org/0000-0002-7224-9222"
type: software
repository-code: "https://github.com/bids-standard/pybv"
url: "https://pybv.readthedocs.io/"
Expand Down
4 changes: 3 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ People who contributed to this software across releases (in **alphabetical order
- `Chris Holdgraf`_
- `Clemens Brunner`_
- `Phillip Alday`_
- `Pierre Cutellic`_
- `Richard Höchenberger`_
- `Stefan Appelhoff`_
- `Tristan Stenner`_
Expand All @@ -23,6 +24,7 @@ People who contributed to this software across releases (in **alphabetical order
.. _Richard Höchenberger: https://hoechenberger.net/
.. _Adam Li: https://adam2392.github.io/
.. _Aniket Pradhan: http://home.iiitd.edu.in/~aniket17133/
.. _Pierre Cutellic: https://github.com/compmonks

.. _changelog:

Expand All @@ -41,7 +43,7 @@ Here we list a changelog of pybv.

Changelog
~~~~~~~~~
- Nothing yet
- Updated ``_chk_events`` to accept label values >= 0, by `Pierre Cutellic`_: (:gh:`95`)

0.7.3 (2022-06-04)
==================
Expand Down
8 changes: 4 additions & 4 deletions pybv/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def write_brainvision(*, data, sfreq, ch_names,
- ``"duration"`` : int
The duration of the event in samples (defaults to ``1``).
- ``"description"`` : str | int
The description of the event. Must be a positive int when
The description of the event. Must be a non-negative int when
`type` (see below) is either ``"Stimulus"`` or ``"Response"``, and may
be a str when `type` is ``"Comment"``.
- ``"type"`` : str
Expand Down Expand Up @@ -438,11 +438,11 @@ def _chk_events(events, ch_names, n_times):
if event["type"] in ["Stimulus", "Response"]:
if not isinstance(event["description"], int):
raise ValueError(f"events: when `type` is {event['type']}, "
"`description` must be positive int")
"`description` must be non-negative int")

if event["description"] < 1:
if event["description"] < 0:
raise ValueError(f"events: when `type` is {event['type']}, "
"descriptions must be positve ints.")
"descriptions must be non-negative ints.")

# NOTE: We format 1 -> "S 1", 10 -> "S 10", 100 -> "S100", etc.,
# https://github.com/bids-standard/pybv/issues/24#issuecomment-512746677
Expand Down
4 changes: 2 additions & 2 deletions pybv/tests/test_bv_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def test_bv_writer_events_array(tmpdir, events_errormsg):
([{"onset": 100, "description": 1, "duration": 0}], "events: at least one duration is too short."), # noqa: E501
([{"onset": 100, "description": 1, "duration": 4901}], "events: at least one event has a duration that exceeds"), # noqa: E501
([{"onset": 1, "description": 2, "type": "bogus"}], "`type` must be one of"), # noqa: E501
([{"onset": 1, "description": "bogus"}], "when `type` is Stimulus, `description` must be positive int"), # noqa: E501
([{"onset": 1, "description": "bogus"}], "when `type` is Stimulus, `description` must be non-negative int"), # noqa: E501
([{"onset": 1, "description": {}, "type": "Comment"}], "when `type` is Comment, `description` must be str or int"), # noqa: E501
([{"onset": 1, "description": -1}], "when `type` is Stimulus, descriptions must be positve ints."), # noqa: E501
([{"onset": 1, "description": -1}], "when `type` is Stimulus, descriptions must be non-negative ints."), # noqa: E501
([{"onset": 1, "description": 1, "channels": "bogus"}], "found channel .* bogus"),
([{"onset": 1, "description": 1, "channels": ["ch_1", "ch_1"]}], "events: found duplicate channel names"), # noqa: E501
([{"onset": 1, "description": 1, "channels": ["ch_1", "ch_2"]}], "warn___feature may not be supported"), # noqa: E501
Expand Down

0 comments on commit 8035d9b

Please sign in to comment.