mne-tools / mne-tools/mne-python

Saving annotations as CSV results in wrong orig_time

Open
#8,573 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

BUG
Dominant language
Python
Stars
3.5k
Forks
1.6k
Avg merge
1d 6h
Merged PRs (30d)
100

Description

Describe the bug

When creating annotations with orig_time=None and saving them to a *.csv file using the save function, orig_time=None is ignored and replaced by 1970-01-01 00:00:00. Thus, when importing the annotations again, the orig_time of the imported annotations differs from the original ones. This seems odd to me and not intended, because the issue does not occur when saving the annotations to *.txt file

Steps to reproduce

Here is a minimal working example:

# Create annotation and save it to CSV file
annotations = mne.Annotations(onset=[2.5], duration=[5], description=["Test"], orig_time=None)
annotations.save("annotation.csv")

# Read annotation from file again
read_annotations = mne.read_annotations("annotation.csv")

# Output orig_time
print(read_annotations[0]['orig_time']) #Outputs 1970-01-01 00:00:02.500000+00:00 instead of None
Expected results

I expected the output to be None. This is even the result when using a *.txt file instead of a *.csv file.

Actual results

1970-01-01 00:00:02.500000+00:00
In the annotations dict, the orig_time is stored as ('orig_time', datetime.datetime(1970, 1, 1, 0, 0, 2, 500000, tzinfo=datetime.timezone.utc))

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the Annotations.save and read_annotations entry points for CSV handling, using the reproduction in the issue to compare CSV and TXT behavior. Confirm that an annotation saved with orig_time=None is imported with orig_time=None, and add or update coverage for this round trip.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.