diff --git a/tests/test_utils.py b/tests/test_utils.py index 57d58cf9e..88a07219d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -17,6 +17,7 @@ import pytest +import numpy as np def test_format_byte_size(): assert format_byte_size(byte_size=12345) == "12.35KB" @@ -145,6 +146,7 @@ def test_calculate_number_of_cpu_negative_value(self): def test_is_ascending_series(): assert is_ascending_series(series=[1, 1, 1]) assert is_ascending_series(series=[1, 2, 3]) + assert is_ascending_series(series=[1, np.nan, 3]) assert not is_ascending_series(series=[1, 2, 1]) diff --git a/tests/unit_tests/test_time_series.py b/tests/unit_tests/test_time_series.py index 88e831603..b47a0336f 100644 --- a/tests/unit_tests/test_time_series.py +++ b/tests/unit_tests/test_time_series.py @@ -12,6 +12,7 @@ check_data_orientation, check_timestamps_match_first_dimension, check_timestamps_ascending, + check_timestamps_with_nans, check_missing_unit, check_resolution, check_timestamp_of_the_first_sample_is_not_negative, @@ -226,6 +227,9 @@ 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]) + 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]) @@ -238,6 +242,31 @@ 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]) + assert check_timestamps_ascending(time_series) == InspectorMessage( + message="test_time_series timestamps are not ascending.", + importance=Importance.BEST_PRACTICE_VIOLATION, + check_function_name="check_timestamps_ascending", + object_type="TimeSeries", + object_name="test_time_series", + 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]) + assert check_timestamps_with_nans(time_series) == InspectorMessage( + message="test_time_series timestamps contain NaN values.", + importance=Importance.BEST_PRACTICE_VIOLATION, + check_function_name="check_timestamps_with_nans", + object_type="TimeSeries", + object_name="test_time_series", + 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])