def test_timeseries():
    from earlywarningsignals.earlywarningsignals import check_time_series

    # Test 1: Trying a known value
    input_1a = np.arange(10) * 2
    input_1b = np.arange(10)
    input_2a = np.array([[1, 6], [3, 5], [4, 4], [6, 1]])
    input_2aa = np.array([['a', 'b'], ['b', 'x'], ['l', 'i'], ['g', 'z']])
    input_2b = np.arange(4)
    input_2bb = np.random.randint(low=0, high=14, size=(4, 1))
    input_3a = pd.DataFrame(input_1a)
    input_3b = pd.DataFrame(input_1b)
    input_4a = pd.DataFrame(input_2a)
    input_4b = pd.DataFrame(input_2b)
    [output_1a, output_1b] = check_time_series(input_1a)
    #still have to write asserts
    assert (isinstance(output_1a, pd.DataFrame))

    #Check if evenly spaced check works
    with pt.raises(ValueError):
        check_time_series(input_2a, input_2bb)

    #Check if timeseries and timeindex have same length
    with pt.raises(ValueError):
        check_time_series(input_3a, input_4b)
def test_check_timeseries_dataframe():
    from earlywarningsignals.earlywarningsignals import check_time_series

    N = 10
    input_vector = np.arange(N)
    input_df = pd.DataFrame(input_vector)
    [ts, indices] = check_time_series(input_df)

    # The indices are correct
    assert (np.min(indices) == 0)
    assert (np.max(indices) == N - 1)
    # The number of elements is correct
    assert (np.size(indices) == N)
    assert (np.size(ts) == N)
def test_check_timeseries_customtimes():
    from earlywarningsignals.earlywarningsignals import check_time_series

    N = 10
    input_vector = np.arange(N)
    input_times = np.linspace(0, 0.9, N)  # 0, 0.1, 0.2, ..., 0.9
    input_df = pd.DataFrame(input_vector, input_times)
    [ts, indices] = check_time_series(input_df)

    # The indices are correct
    assert (indices.all() == input_times.all())

    # The number of elements is correct
    assert (np.size(indices) == N)
    assert (np.size(ts) == N)
def test_check_timeseries_array():
    from earlywarningsignals.earlywarningsignals import check_time_series

    input_array = np.array([[1, 6], [3, 5], [4, 4], [6, 1]])
    [ts, indices] = check_time_series(input_array)

    # The indices are correct
    assert (np.min(indices) == 0)
    assert (np.max(indices) == 4 - 1)

    # The number of elements is correct
    assert (np.size(indices) == 4)

    # The output is a dataframe
    assert (isinstance(ts, pd.DataFrame))