def test_concat_fails_iterable(test_pd_df): """Check that calling concat with a non-iterable raises""" msg = "First argument must be an iterable, you passed an object of type '{}'!" for dfs, type_ in [(1, "int"), ("foo", "str"), (test_pd_df, "DataFrame")]: with pytest.raises(TypeError, match=msg.format(type_)): concat(dfs)
def test_concat_incompatible_cols(test_pd_df): """Check that calling concat on a single-item list returns identical object""" df1 = IamDataFrame(test_pd_df) test_pd_df["extra_col"] = "foo" df2 = IamDataFrame(test_pd_df) match = "Items have incompatible timeseries data index dimensions!" with pytest.raises(ValueError, match=match): concat([df1, df2])
def test_concat(test_df): left = IamDataFrame(test_df.data.copy()) right = left.data.copy() right['model'] = 'not left' right = IamDataFrame(right) result = concat([left, right]) obs = result.data.reset_index(drop=True) exp = pd.concat([left.data, right.data]).reset_index(drop=True) pd.testing.assert_frame_equal(obs, exp) obs = result.meta.reset_index(drop=True) exp = pd.concat([left.meta, right.meta]).reset_index(drop=True) pd.testing.assert_frame_equal(obs, exp)
def test_concat_incompatible_time(test_df_year, test_df_time): """Check that calling concat with incompatible time formats raises""" match = re.escape( "Items have incompatible time format ('year' vs. 'time')!") with pytest.raises(ValueError, match=match): concat([test_df_year, test_df_time])
def test_concat_single_item(test_df): """Check that calling concat on a single-item list returns identical object""" obs = concat([test_df]) assert_iamframe_equal(obs, test_df)