From dd423506a221f2e2e45d9380545592c95e203797 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Jul 2024 13:27:56 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/nwbinspector/checks/time_series.py | 2 ++ tests/test_utils.py | 1 + tests/unit_tests/test_time_series.py | 18 +++++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/nwbinspector/checks/time_series.py b/src/nwbinspector/checks/time_series.py index c59ddc587..04b114865 100644 --- a/src/nwbinspector/checks/time_series.py +++ b/src/nwbinspector/checks/time_series.py @@ -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): """ diff --git a/tests/test_utils.py b/tests/test_utils.py index 88a07219d..5ff3781bc 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -19,6 +19,7 @@ import numpy as np + def test_format_byte_size(): assert format_byte_size(byte_size=12345) == "12.35KB" diff --git a/tests/unit_tests/test_time_series.py b/tests/unit_tests/test_time_series.py index b47a0336f..2d49033c0 100644 --- a/tests/unit_tests/test_time_series.py +++ b/tests/unit_tests/test_time_series.py @@ -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( @@ -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, @@ -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, @@ -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 = (