From 648e639d5531e92c5104ac73ddcdca9e5017b544 Mon Sep 17 00:00:00 2001 From: Marc Weitz <marc.weitz@onlinehome.de> Date: Wed, 28 Apr 2021 08:42:29 +0200 Subject: [PATCH] raises NotImplementedError for certain sampling frequencies (see #10) --- paat/io.py | 5 ++--- tests/test_io.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/paat/io.py b/paat/io.py index aefa633..8f5c6f6 100644 --- a/paat/io.py +++ b/paat/io.py @@ -348,7 +348,7 @@ def _create_time_array(time_data, hz=100): # check if the sampling frequenzy can fit into equal parts within a 1000ms window if 1000 % hz != 0: - logging.error('Sampling frequenzy {} cannot be split into equal parts within a 1s window'.format(hz)) + raise NotImplementedError("Creating time array does not support sampling frequencies other than 100hz yet. See https://github.com/Trybnetic/paat/issues/10") # calculate the step size of hz in 1s (so 100hz means 100 measurements in 1sec, so if we need to fill 1000ms then we need use a step size of 10) step_size = 1000 / hz @@ -438,8 +438,7 @@ def _create_time_vector(start, n_samples, hz): # check if the sampling frequenzy can fit into equal parts within a nanosecond window if ms_in_sec % hz != 0: - logging.error('Sampling frequenzy {} cannot be split into equal parts within a 1s window'.format(hz)) - exit(1) + raise NotImplementedError("Creating time vector does not support sampling frequencies other than 100hz yet. See https://github.com/Trybnetic/paat/issues/10") step_size = ms_in_sec / hz diff --git a/tests/test_io.py b/tests/test_io.py index 64a5292..d01afa7 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -3,6 +3,7 @@ import numpy as np import h5py +import pytest from paat import io @@ -29,3 +30,18 @@ def test_hdf5(): for key, value in meta.items(): assert meta[key] == new_meta[key] + + +def test_exceptions(): + with pytest.raises(NotImplementedError) as e_info: + time_data = np.arange(10) + hz = 33 + io._create_time_array(time_data, hz) + assert e_info + + with pytest.raises(NotImplementedError) as e_info: + start = np.asarray(np.datetime64('today'), dtype='datetime64[ms]') + n_samples = 330 + hz = 33 + io._create_time_vector(start, n_samples, hz) + assert e_info