Skip to content
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

Fix Annotations time formats #13109

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

tsbinns
Copy link
Contributor

@tsbinns tsbinns commented Feb 10, 2025

Reference issue (if any)

Fixes #13108

What does this implement/fix?

When reading annotations from a csv file, truncates nanoseconds from orig_time by converting to the microsecond format. The exception is for the default time of 1970-01-01 00:00:00 used in the files when Annotations.orig_time=None, as converting this to microseconds would cause it to be read as a proper time rather than being converted to None which is intended.

Also truncates nanoseconds from the times in utils.dataframes._convert_times() when time_format="datetime" by converting to dtype=datetime64[us].
Should this also be done when time_format="timedelta"?

Finally, updates unit tests that check csv files with nanosecond times get assigned proper orig_time when read in and checks that Annotations.to_data_frame() returns times with nanoseconds truncated (which in turn means truncated times are saved).

@tsbinns
Copy link
Contributor Author

tsbinns commented Feb 10, 2025

Also updated the docstring for Annotations.orig_time and added a RuntimeWarning when a string is provided but it gets converted to None. Thoughts on this?

@tsbinns
Copy link
Contributor Author

tsbinns commented Feb 10, 2025

The code for annotations works fine, but changing _convert_times() has some knock on effects for converting data objects to dataframes.

This is an alternative approach to fix the current errors:

elif time_format == "datetime":
    # make ISO8601 (microsecond) compatible
    times = (to_timedelta(times + first_time, unit="s") + meas_date).to_numpy()
    times = DatetimeIndex(
        [time.replace(nanosecond=0) for time in times], tz=times[0].tz
    )

but I'm not 100% on how others want to proceed so I'll pause for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Annotations.orig_time not properly read from csv files
1 participant