Repository: bids-standard/pybv

Issue:
Update to MNE 0.18 and prepare for MNE 0.19
Our tests fail with MNE 0.18:

```Shell
___________________________ test_bv_writer_oi_cycle ____________________________

    def test_bv_writer_oi_cycle():
        """Test that a write-read cycle produces identical data."""
        tmpdir = _mktmpdir()
    
        # Write, then read the data to BV format
        write_brainvision(data, sfreq, ch_names, fname, tmpdir, events=events,
                          resolution=np.power(10., -np.arange(10)))
        raw_written = mne.io.read_raw_brainvision(op.join(tmpdir, fname + '.vhdr'),
                                                  preload=True, stim_channel=False)
        # Delete the first annotation because it's just marking a new segment
        raw_written.annotations.delete(0)
        # Convert our annotations to events
        events_written, event_id = mne.events_from_annotations(raw_written)
    
        # sfreq
        assert sfreq == raw_written.info['sfreq']
    
        # Event timing should be within one index of originals
        assert_allclose(events[:, 0], events_written[:, 0], 1)
>       assert_array_equal(events[:, 1], events_written[:, 2])
E       AssertionError: 
E       Arrays are not equal
E       
E       Mismatch: 100%
E       Max absolute difference: 10000
E       Max relative difference: 0.99990001
E        x: array([1, 1, 2, 2])
E        y: array([10001, 10001, 10002, 10002])

pybv/tests/test_bv_writer.py:97: AssertionError
```


and in MNE 0.19.dev0, the stim_channel will be gone: https://github.com/mne-tools/mne-python/pull/6348/files

--> which makes this test fail as well:

```Shell
=================================== FAILURES ===================================
___________________________ test_bv_writer_oi_cycle ____________________________

    def test_bv_writer_oi_cycle():
        """Test that a write-read cycle produces identical data."""
        tmpdir = _mktmpdir()
    
        # Write, then read the data to BV format
        write_brainvision(data, sfreq, ch_names, fname, tmpdir, events=events,
                          resolution=np.power(10., -np.arange(10)))
        raw_written = mne.io.read_raw_brainvision(op.join(tmpdir, fname + '.vhdr'),
>                                                 preload=True, stim_channel=False)
E       TypeError: read_raw_brainvision() got an unexpected keyword argument 'stim_channel'

pybv/tests/test_bv_writer.py:86: TypeError

```



Comments:

Patch:
diff --git a/README.rst b/README.rst
index b9ab195..248c3b0 100644
--- a/README.rst
+++ b/README.rst
@@ -1,5 +1,3 @@
-
-
 .. image:: https://circleci.com/gh/bids-standard/pybv.svg?style=svg
    :target: https://circleci.com/gh/bids-standard/pybv
    :alt: CircleCI
@@ -8,6 +6,9 @@
    :target: https://codecov.io/gh/bids-standard/pybv
    :alt: codecov
 
+.. image:: https://badge.fury.io/py/pybv.svg
+   :target: https://badge.fury.io/py/pybv
+
 .. image:: https://pepy.tech/badge/pybv
    :target: https://pepy.tech/project/pybv
    :alt: Downloads
@@ -111,8 +112,7 @@ Here is an example of the MNE code required to read in BrainVision data:
     import mne
 
     # Import the BrainVision data into an MNE Raw object
-    raw = mne.io.read_raw_brainvision('tmp/test.vhdr', preload=True,
-                                      stim_channel=False)
+    raw = mne.io.read_raw_brainvision('tmp/test.vhdr', preload=True)
 
     # Read in the event information as MNE annotations
     annot = mne.read_annotations('tmp/test.vmrk')
diff --git a/docs/changelog.rst b/docs/changelog.rst
index ad42263..4e671ea 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -14,14 +14,27 @@ Here we list a changelog of pybv.
 
 current
 =======
+
+Changelog
+~~~~~~~~~
 Add binary format parameter to public API by `Tristan Stenner`_ (`#22 <https://github.com/bids-standard/pybv/pull/22>`_)
 
+Bug
+~~~
+fix bug with events that only have integer codes of length less than 3, by `Stefan Appelhoff`_ (`#26 <https://github.com/bids-standard/pybv/pull/26>`_)
+
 0.0.2
 =====
+
+Changelog
+~~~~~~~~~
 Support channel-specific scaling factors by `Tristan Stenner`_ (`#17 <https://github.com/bids-standard/pybv/pull/17>`_)
 
 0.0.1
 =====
+
+Changelog
+~~~~~~~~~
 Initial import from palday's philistine package and removing dependency on MNE-Python, by `Chris Holdgraf`_ and `Stefan Appelhoff`_
 
 .. _Chris Holdgraf: https://bids.berkeley.edu/people/chris-holdgraf
diff --git a/pybv/__init__.py b/pybv/__init__.py
index 1a07b00..1da4f72 100644
--- a/pybv/__init__.py
+++ b/pybv/__init__.py
@@ -8,6 +8,6 @@
 #
 # License: BSD (3-clause)
 
-__version__ = '0.1.0.dev0'
+__version__ = '0.3.dev0'
 
 from .io import (write_brainvision, )  # noqa: F401
diff --git a/pybv/io.py b/pybv/io.py
index f084169..ba6615f 100644
--- a/pybv/io.py
+++ b/pybv/io.py
@@ -156,8 +156,13 @@ def _write_vmrk_file(vmrk_fname, eeg_fname, events):
         if events is None or len(events) == 0:
             return
 
-        # Handle events
+        # Handle events: We write all of them as "Stimulus" events for now.
+        # This is a string staring with "S" and followed by an integer of
+        # minimum length 3, padded with "space" if the integer is < length 3.
+        # For example "S  1", "S 23", "S345"
+        # XXX: see https://github.com/bids-standard/pybv/issues/24#issuecomment-512746677  # noqa: E501
         twidth = int(np.ceil(np.log10(np.max(events[:, 1]))))
+        twidth = twidth if twidth > 3 else 3
         tformat = 'S{:>' + str(twidth) + '}'
 
         for ii, irow in enumerate(range(len(events)), start=2):
diff --git a/requirements.txt b/requirements.txt
index e8fdf42..301052e 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,5 @@
 numpy
-mne==0.17
+mne>0.17
 pytest
 pytest-cov
 coverage


Test patch:
diff --git a/pybv/tests/test_bv_writer.py b/pybv/tests/test_bv_writer.py
index 877d843..b5ff9e9 100644
--- a/pybv/tests/test_bv_writer.py
+++ b/pybv/tests/test_bv_writer.py
@@ -82,8 +82,8 @@ def test_bv_writer_oi_cycle():
     # Write, then read the data to BV format
     write_brainvision(data, sfreq, ch_names, fname, tmpdir, events=events,
                       resolution=np.power(10., -np.arange(10)))
-    raw_written = mne.io.read_raw_brainvision(op.join(tmpdir, fname + '.vhdr'),
-                                              preload=True, stim_channel=False)
+    vhdr_fname = op.join(tmpdir, fname + '.vhdr')
+    raw_written = mne.io.read_raw_brainvision(vhdr_fname, preload=True)
     # Delete the first annotation because it's just marking a new segment
     raw_written.annotations.delete(0)
     # Convert our annotations to events