def test_apply_to_timeseries_with_uni_dim(self): cumprod = CumProd(mock_dataset.fields.wins) result = cumprod.apply(dimx2_date_str_df, None) expected = pd.Series([2] + [0] * 12, name='$wins', index=dimx2_date_str_df.index) pandas.testing.assert_series_equal(expected, result)
def test_apply_to_timeseries_with_uni_dim(self): cumprod = CumProd(slicer.metrics.wins) result = cumprod.apply(cont_uni_dim_df, None) expected = pd.Series([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], name='$m$wins', index=cont_uni_dim_df.index) pandas.testing.assert_series_equal(expected, result)
def test_apply_to_timeseries(self): cumprod = CumProd(mock_dataset.fields.wins) result = cumprod.apply(dimx1_date_df, None) expected = pd.Series([2, 4, 8, 16, 32, 64], name='$wins', index=dimx1_date_df.index) pandas.testing.assert_series_equal(expected, result)
def test_apply_to_timeseries_with_uni_dim_and_ref(self): cumprod = CumProd(slicer.metrics.wins) result = cumprod.apply(cont_uni_dim_ref_df, ElectionOverElection(slicer.dimensions.timestamp)) expected = pd.Series([1., 1, 1, 1, 1, 1, 1, 1, 1, 1], name='$m$wins_eoe', index=cont_uni_dim_ref_df.index) pandas.testing.assert_series_equal(expected, result)
def test_apply_to_timeseries_with_uni_dim_and_ref(self): cumprod = CumProd(slicer.metrics.wins) result = cumprod.apply( cont_uni_dim_ref_df, ElectionOverElection(slicer.dimensions.timestamp)) expected = pd.Series([1., 1, 1, 1, 1, 1, 1, 1, 1, 1], name='$m$wins_eoe', index=cont_uni_dim_ref_df.index) pandas.testing.assert_series_equal(expected, result)
def test_apply_to_timeseries_with_uni_dim_and_ref(self): cumprod = CumProd(mock_dataset.fields.wins) result = cumprod.apply( dimx2_date_str_ref_df, ElectionOverElection(mock_dataset.fields.timestamp)) expected = pd.Series([2.0] + [0.0] * 10, name='$wins_eoe', index=dimx2_date_str_ref_df.index) pandas.testing.assert_series_equal(expected, result)
def test_apply_cummulative_for_delta_percent(self): dataset = MagicMock() dataset.table._table_name = "table" field = Field("value", None) cumsum = CumProd(field) reference = Reference(field, WeekOverWeek, delta=True, delta_percent=True) df = pd.DataFrame.from_dict({ "$value": [55, 60, 108], "$cumprod(value)": [55, 3300, 356400], "$value_wow_delta_percent": [10, 20, 8], }) result = cumsum.apply(df, reference) pandas.testing.assert_series_equal(pd.Series([10.0, 32.0, 42.56]), result)