コード例 #1
0
ファイル: test_computations.py プロジェクト: iiasa/ixmp
def test_store_ts(request, caplog, test_mp):
    # Computer and target scenario
    c = Computer()

    # Target scenario
    model_name = __name__
    scenario_name = "test scenario"
    scen = Scenario(test_mp, model_name, scenario_name, version="new")
    scen.commit("Empty scenario")
    c.add("target", scen)

    # Add test data to the Computer: a pd.DataFrame
    input_1 = test_data[0].assign(variable="Foo")
    c.add("input 1", input_1)

    # A pyam.IamDataFrame
    input_2 = test_data[2050].assign(variable="Bar")
    c.add("input 2", pyam.IamDataFrame(input_2))

    # Expected results: same as input, but with the `model` and `scenario` columns
    # filled automatically.
    expected_1 = input_1.assign(model=model_name, scenario=scenario_name)
    expected_2 = input_2.assign(model=model_name, scenario=scenario_name)

    # Task to update the scenario with the data
    c.add("test 1", store_ts, "target", "input 1", "input 2")

    # Scenario starts empty of time series data
    assert 0 == len(scen.timeseries())

    # The computation runs successfully
    c.get("test 1")

    # All rows from both inputs are present
    assert len(input_1) + len(input_2) == len(scen.timeseries())

    # Input is stored exactly
    assert_frame_equal(expected_1, scen.timeseries(variable="Foo"))
    assert_frame_equal(expected_2, scen.timeseries(variable="Bar"))
コード例 #2
0
def test_timeseries_remove_all_data(mp):
    args_all = ('Douglas Adams', 'test_remove_all')

    scen = Scenario(mp, *args_all, version='new', annotation='fo')
    scen.add_timeseries(DATA['timeseries'].pivot_table(values='value',
                                                       index=IDX_COLS))
    scen.commit('importing a testing timeseries')

    scen = Scenario(mp, *args_all)
    assert_timeseries(scen, DATA['timeseries'])

    exp = DATA['timeseries'].copy()
    exp['variable'] = 'Testing2'

    scen.check_out()
    scen.add_timeseries(exp)
    scen.remove_timeseries(DATA['timeseries'])
    scen.commit('testing for removing a full timeseries row')

    assert scen.timeseries(region='World', variable='Testing').empty
    assert_timeseries(scen, exp)
コード例 #3
0
ファイル: test_timeseries.py プロジェクト: mitterrutzner/ixmp
def test_timeseries_remove_all_data(mp):
    args_all = ("Douglas Adams", "test_remove_all")

    scen = Scenario(mp, *args_all, version="new", annotation="fo")
    scen.add_timeseries(DATA["timeseries"].pivot_table(values="value",
                                                       index=IDX_COLS))
    scen.commit("importing a testing timeseries")

    scen = Scenario(mp, *args_all)
    assert_timeseries(scen, DATA["timeseries"])

    exp = DATA["timeseries"].copy()
    exp["variable"] = "Testing2"

    scen.check_out()
    scen.add_timeseries(exp)
    scen.remove_timeseries(DATA["timeseries"])
    scen.commit("testing for removing a full timeseries row")

    assert scen.timeseries(region="World", variable="Testing").empty
    assert_timeseries(scen, exp)