def test_init_empty_message(test_pd_df, caplog): tdf = test_pd_df.copy() tdf["extra_col"] = "test_val" tdf["extra_col"] = np.nan res = IamDataFrame(tdf) assert "Primary Energy|Coal" not in res.variables().tolist() drop_message = ( "Formatted data is empty! (perhaps there is a column full of nans?)") message_idx = caplog.messages.index(drop_message) assert caplog.records[message_idx].levelno == logging.WARNING
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
def test_read_pandas(): df = IamDataFrame(os.path.join(TEST_DATA_DIR, 'testing_data_2.csv')) assert list(df.variables()) == ['Primary Energy']