Ejemplo n.º 1
0
def test_init_from_iamdf(test_df_year):
    # casting an IamDataFrame instance again works
    df = IamDataFrame(test_df_year)

    # inplace-operations on the new object have effects on the original object
    df.rename(scenario={'scen_a': 'scen_foo'}, inplace=True)
    assert all(test_df_year.scenarios().values == ['scen_b', 'scen_foo'])

    # overwrites on the new object do not have effects on the original object
    df = df.rename(scenario={'scen_foo': 'scen_bar'})
    assert all(df.scenarios().values == ['scen_b', 'scen_bar'])
    assert all(test_df_year.scenarios().values == ['scen_b', 'scen_foo'])
Ejemplo n.º 2
0
def test_require_variable_year_list(test_df):
    years = [2005, 2010]

    # checking for variables that have ANY of the years in the list
    df = IamDataFrame(test_df.data[1:])
    df.require_variable(variable='Primary Energy',
                        year=years,
                        exclude_on_fail=True)
    df.filter(exclude=False, inplace=True)

    assert len(df.variables()) == 2
    assert len(df.scenarios()) == 2

    # checking for variables that have ALL of the years in the list
    df = IamDataFrame(test_df.data[1:])
    for y in years:
        df.require_variable(variable='Primary Energy',
                            year=y,
                            exclude_on_fail=True)
    df.filter(exclude=False, inplace=True)

    assert len(df.variables()) == 1
    assert len(df.scenarios()) == 1