-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a function
compare()
to compare two IamDataFrames (#174)
* add a function to compare two IamDataFrames * appease stickler * add to release notes * refactor to `compare()` * remove print
- Loading branch information
1 parent
22c0b45
commit 8a6ca9c
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import copy | ||
import numpy as np | ||
import pandas as pd | ||
from pyam import compare, IAMC_IDX | ||
|
||
|
||
def test_compare(meta_df): | ||
clone = copy.deepcopy(meta_df) | ||
clone.data.iloc[0, clone.data.columns.get_loc('value')] = 2 | ||
clone.rename({'variable': {'Primary Energy|Coal': 'Primary Energy|Gas'}}, | ||
inplace=True) | ||
|
||
obs = compare(meta_df, clone, right_label='meta_df', left_label='clone') | ||
|
||
exp = pd.DataFrame([ | ||
['Primary Energy', 'EJ/y', 2005, 2, 1], | ||
['Primary Energy|Coal', 'EJ/y', 2005, np.nan, 0.5], | ||
['Primary Energy|Coal', 'EJ/y', 2010, np.nan, 3], | ||
['Primary Energy|Gas', 'EJ/y', 2005, 0.5, np.nan], | ||
['Primary Energy|Gas', 'EJ/y', 2010, 3, np.nan], | ||
], | ||
columns=['variable', 'unit', 'year', 'meta_df', 'clone'], | ||
) | ||
exp['model'] = 'a_model' | ||
exp['scenario'] = 'a_scenario' | ||
exp['region'] = 'World' | ||
exp = exp.set_index(IAMC_IDX + ['year']) | ||
|
||
pd.testing.assert_frame_equal(obs, exp) |