def test_mean_2(date_func):
    s1mask = s1(date_func).mask((
        timestamp(2020, 1, 2, date_func=date_func, use_str=True),
        timestamp(2020, 1, 4, date_func=date_func, use_str=True),
    ))
    s2mask = (s2(date_func).mask((
        timestamp(2020, 1, 7, date_func=date_func, use_str=True),
        timestamp(2020, 1, 9, date_func=date_func, use_str=True),
    )).mask((None, timestamp(2019, 12, 31, date_func=date_func,
                             use_str=True))))
    result = sc.mean([s1mask, s2mask])
    pd.testing.assert_series_equal(
        result.step_values,
        pd.Series({
            timestamp(2019, 12, 31, date_func=date_func): -1.75,
            timestamp(2020, 1, 1, date_func=date_func): -1.125,
            timestamp(2020, 1, 2, date_func=date_func): np.nan,
            timestamp(2020, 1, 4, date_func=date_func): 1.125,
            timestamp(2020, 1, 5, date_func=date_func): 0.75,
            timestamp(2020, 1, 6, date_func=date_func): -0.5,
            timestamp(2020, 1, 7, date_func=date_func): np.nan,
            timestamp(2020, 1, 9, date_func=date_func): -1.5,
            timestamp(2020, 1, 10, date_func=date_func): 0.0,
            timestamp(2020, 1, 11, date_func=date_func): 2.5,
            timestamp(2020, 1, 13, date_func=date_func): 0.0,
        }),
        check_names=False,
        check_index_type=False,
    )
    assert np.isnan(result.initial_value)
def test_mean_1(date_func):
    s1mask = s1(date_func).mask((
        timestamp(2020, 1, 2, date_func=date_func, use_str=True),
        timestamp(2020, 1, 4, date_func=date_func, use_str=True),
    ))
    s2mask = s2(date_func).mask((
        timestamp(2020, 1, 7, date_func=date_func, use_str=True),
        timestamp(2020, 1, 9, date_func=date_func, use_str=True),
    ))
    pd.testing.assert_series_equal(
        sc.mean([s1mask, s2mask]).step_values,
        pd.Series({
            timestamp(2019, 12, 27, date_func=date_func): -0.875,
            timestamp(2019, 12, 29, date_func=date_func): -1.75,
            timestamp(2020, 1, 1, date_func=date_func): -1.125,
            timestamp(2020, 1, 2, date_func=date_func): np.nan,
            timestamp(2020, 1, 4, date_func=date_func): 1.125,
            timestamp(2020, 1, 5, date_func=date_func): 0.75,
            timestamp(2020, 1, 6, date_func=date_func): -0.5,
            timestamp(2020, 1, 7, date_func=date_func): np.nan,
            timestamp(2020, 1, 9, date_func=date_func): -1.5,
            timestamp(2020, 1, 10, date_func=date_func): 0.0,
            timestamp(2020, 1, 11, date_func=date_func): 2.5,
            timestamp(2020, 1, 13, date_func=date_func): 0.0,
        }),
        check_names=False,
        check_index_type=False,
    )
def test_mean_1():
    s1mask = s1().mask((2, 4))
    s2mask = s2().mask((7, 9))
    pd.testing.assert_series_equal(
        sc.mean([s1mask, s2mask]).step_values,
        pd.Series({
            -4.0: -0.875,
            -2.0: -1.75,
            1.0: -1.125,
            2.0: np.nan,
            4.0: 1.125,
            5.0: 0.75,
            6.0: -0.5,
            7.0: np.nan,
            9.0: -1.5,
            10.0: 0.0,
            11.0: 2.5,
            13.0: 0.0,
        }),
        check_names=False,
        check_index_type=False,
    )
def test_mean_3(IS1, IS2):
    pd.testing.assert_series_equal(
        sc.mean(np.array([IS1, IS2])).step_changes,
        pd.Series(
            {
                -4.0: -0.875,
                -2.0: -0.875,
                1.0: 0.625,
                2.0: 2.25,
                2.5: -1.25,
                3.0: 1.25,
                4.0: 1.25,
                5.0: -2.625,
                6.0: -1.25,
                7.0: 1.25,
                8.0: 2.5,
                10.0: -2.25,
            }
        ),
        check_names=False,
        check_index_type=False,
    )
def test_mean_2():
    s1mask = s1().mask((2, 4))
    s2mask = s2().mask((7, 9)).mask((None, 0))
    result = sc.mean([s1mask, s2mask])
    pd.testing.assert_series_equal(
        result.step_values,
        pd.Series({
            0.0: -1.75,
            1.0: -1.125,
            2.0: np.nan,
            4.0: 1.125,
            5.0: 0.75,
            6.0: -0.5,
            7.0: np.nan,
            9.0: -1.5,
            10.0: 0.0,
            11.0: 2.5,
            13.0: 0.0,
        }),
        check_names=False,
        check_index_type=False,
    )
    assert np.isnan(result.initial_value)