Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 30, 2024
1 parent 0845258 commit dd42350
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/nwbinspector/checks/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ def check_timestamps_ascending(time_series: TimeSeries, nelems=200):
if time_series.timestamps is not None and not is_ascending_series(time_series.timestamps, nelems=nelems):
return InspectorMessage(f"{time_series.name} timestamps are not ascending.")


@register_check(importance=Importance.BEST_PRACTICE_VIOLATION, neurodata_type=TimeSeries)
def check_timestamps_with_nans(time_series: TimeSeries):
"""Check if there are NaN values in the timestamps array."""
if time_series.timestamps is not None and np.isnan(time_series.timestamps).any():
return InspectorMessage(f"{time_series.name} timestamps contain NaN values.")


@register_check(importance=Importance.BEST_PRACTICE_SUGGESTION, neurodata_type=TimeSeries)
def check_timestamp_of_the_first_sample_is_not_negative(time_series: TimeSeries):
"""
Expand Down
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import numpy as np


def test_format_byte_size():
assert format_byte_size(byte_size=12345) == "12.35KB"

Expand Down
18 changes: 15 additions & 3 deletions tests/unit_tests/test_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,14 @@ def test_pass_check_timestamps_ascending_pass():
time_series = pynwb.TimeSeries(name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[1, 2, 3])
assert check_timestamps_ascending(time_series) is None


def test_pass_check_timestamps_ascending_with_nans_pass():
time_series = pynwb.TimeSeries(name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[1, np.nan, 3])
time_series = pynwb.TimeSeries(
name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[1, np.nan, 3]
)
assert check_timestamps_ascending(time_series) is None


def test_check_timestamps_ascending_fail():
time_series = pynwb.TimeSeries(name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[1, 3, 2])
assert check_timestamps_ascending(time_series) == InspectorMessage(
Expand All @@ -242,8 +246,11 @@ def test_check_timestamps_ascending_fail():
location="/",
)


def test_check_timestamps_ascending_with_nans_fail():
time_series = pynwb.TimeSeries(name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[np.nan, 3, 2])
time_series = pynwb.TimeSeries(
name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[np.nan, 3, 2]
)
assert check_timestamps_ascending(time_series) == InspectorMessage(
message="test_time_series timestamps are not ascending.",
importance=Importance.BEST_PRACTICE_VIOLATION,
Expand All @@ -253,12 +260,16 @@ def test_check_timestamps_ascending_with_nans_fail():
location="/",
)


def test_check_timestamps_with_nans_pass():
time_series = pynwb.TimeSeries(name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[1, 2, 3])
assert check_timestamps_with_nans(time_series) is None


def test_check_timestamps_with_nans_fail():
time_series = pynwb.TimeSeries(name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[np.nan, 2, 3])
time_series = pynwb.TimeSeries(
name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[np.nan, 2, 3]
)
assert check_timestamps_with_nans(time_series) == InspectorMessage(
message="test_time_series timestamps contain NaN values.",
importance=Importance.BEST_PRACTICE_VIOLATION,
Expand All @@ -268,6 +279,7 @@ def test_check_timestamps_with_nans_fail():
location="/",
)


def test_check_timestamp_of_the_first_sample_is_not_negative_with_timestamps_fail():
time_series = pynwb.TimeSeries(name="test_time_series", unit="test_units", data=[1, 2, 3], timestamps=[-1, 0, 1])
message = (
Expand Down

0 comments on commit dd42350

Please sign in to comment.