def test_timeseries_edit(mp): scen = TimeSeries(mp, *test_args) df = {'region': ['World'] * 2, 'variable': ['Testing'] * 2, 'unit': ['???', '???'], 'year': [2010, 2020], 'value': [23.7, 23.8]} exp = pd.DataFrame.from_dict(df) obs = scen.timeseries() npt.assert_array_equal(exp[IDX_COLS], obs[IDX_COLS]) npt.assert_array_almost_equal(exp['value'], obs['value']) scen.check_out(timeseries_only=True) df = {'region': ['World'] * 2, 'variable': ['Testing'] * 2, 'unit': ['???', '???'], 'year': [2010, 2020], 'value': [23.7, 23.8]} df = pd.DataFrame.from_dict(df) scen.add_timeseries(df) scen.commit('testing of editing timeseries (same years)') scen.check_out(timeseries_only=True) df = {'region': ['World'] * 3, 'variable': ['Testing', 'Testing', 'Testing2'], 'unit': ['???', '???', '???'], 'year': [2020, 2030, 2030], 'value': [24.8, 24.9, 25.1]} df = pd.DataFrame.from_dict(df) scen.add_timeseries(df) scen.commit('testing of editing timeseries (other years)') mp.close_db() mp.open_db() scen = TimeSeries(mp, *test_args) obs = scen.timeseries().sort_values(by=['year']) df = df.append(exp.loc[0]).sort_values(by=['year']) npt.assert_array_equal(df[IDX_COLS], obs[IDX_COLS]) npt.assert_array_almost_equal(df['value'], obs['value'])
def test_timeseries_edit(mp): scen = TimeSeries(mp, *test_args) df = { "region": ["World"] * 2, "variable": ["Testing"] * 2, "unit": ["???", "???"], "year": [2010, 2020], "value": [23.7, 23.8], } exp = pd.DataFrame.from_dict(df) obs = scen.timeseries() npt.assert_array_equal(exp[IDX_COLS], obs[IDX_COLS]) npt.assert_array_almost_equal(exp["value"], obs["value"]) scen.check_out(timeseries_only=True) df = { "region": ["World"] * 2, "variable": ["Testing"] * 2, "unit": ["???", "???"], "year": [2010, 2020], "value": [23.7, 23.8], } df = pd.DataFrame.from_dict(df) scen.add_timeseries(df) scen.commit("testing of editing timeseries (same years)") scen.check_out(timeseries_only=True) df = { "region": ["World"] * 3, "variable": ["Testing", "Testing", "Testing2"], "unit": ["???", "???", "???"], "year": [2020, 2030, 2030], "value": [24.8, 24.9, 25.1], } df = pd.DataFrame.from_dict(df) scen.add_timeseries(df) scen.commit("testing of editing timeseries (other years)") mp.close_db() mp.open_db() scen = TimeSeries(mp, *test_args) obs = scen.timeseries().sort_values(by=["year"]) df = df.append(exp.loc[0]).sort_values(by=["year"]) npt.assert_array_equal(df[IDX_COLS], obs[IDX_COLS]) npt.assert_array_almost_equal(df["value"], obs["value"])
def test_get_timeseries_iamc(mp): scen = TimeSeries(mp, *test_args) obs = scen.timeseries(region='World', variable='Testing', iamc=True) exp = DATA['timeseries'].pivot_table(index=['region', 'variable', 'unit'], columns='year')['value'].reset_index() exp['model'] = 'Douglas Adams' exp['scenario'] = 'Hitchhiker' npt.assert_array_equal(exp[IAMC_IDX], obs[IAMC_IDX]) npt.assert_array_almost_equal(exp[2010], obs[2010])
def test_get_timeseries_iamc(mp): scen = TimeSeries(mp, *test_args) obs = scen.timeseries(region="World", variable="Testing", iamc=True) exp = (DATA["timeseries"].pivot_table( index=["region", "variable", "unit"], columns="year")["value"].reset_index()) exp["model"] = "Douglas Adams" exp["scenario"] = "Hitchhiker" npt.assert_array_equal(exp[IAMC_IDX], obs[IAMC_IDX]) npt.assert_array_almost_equal(exp[2010], obs[2010])