From 6b5688d566e1abe69307e3174d8d76bf6119eff2 Mon Sep 17 00:00:00 2001 From: Zebedee Nicholls Date: Tue, 14 May 2019 13:07:00 +1000 Subject: [PATCH] Appease stickler --- pyam/core.py | 2 +- tests/test_cast_to_iamc.py | 10 ++++++---- tests/test_core.py | 33 +++++++++++++-------------------- tests/test_feature_compare.py | 2 +- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/pyam/core.py b/pyam/core.py index fab07c0db..c950cd4f6 100644 --- a/pyam/core.py +++ b/pyam/core.py @@ -323,7 +323,7 @@ def swap_time_for_year(self, inplace=False): "time" is not a column of `self.data` """ if "time" not in self.data: - raise ValueError("`time` must be in `self.data` to use this method") + raise ValueError("time column must be datetime to use this method") ret = copy.deepcopy(self) if not inplace else self diff --git a/tests/test_cast_to_iamc.py b/tests/test_cast_to_iamc.py index f152de2d9..68b07e112 100644 --- a/tests/test_cast_to_iamc.py +++ b/tests/test_cast_to_iamc.py @@ -7,11 +7,13 @@ def test_cast_from_value_col(meta_df): + five = dt.datetime(2005, 6, 17) + ten = dt.datetime(2010, 7, 21) df_with_value_cols = pd.DataFrame([ - ['model_a', 'scen_a', 'World', 'EJ/y', dt.datetime(2005, 6, 17), 1, 0.5], - ['model_a', 'scen_a', 'World', 'EJ/y', dt.datetime(2010, 7, 21), 6., 3], - ['model_a', 'scen_b', 'World', 'EJ/y', dt.datetime(2005, 6, 17), 2, None], - ['model_a', 'scen_b', 'World', 'EJ/y', dt.datetime(2010, 7, 21), 7, None] + ['model_a', 'scen_a', 'World', 'EJ/y', five, 1, 0.5], + ['model_a', 'scen_a', 'World', 'EJ/y', ten, 6., 3], + ['model_a', 'scen_b', 'World', 'EJ/y', five, 2, None], + ['model_a', 'scen_b', 'World', 'EJ/y', ten, 7, None] ], columns=['model', 'scenario', 'region', 'unit', 'time', 'Primary Energy', 'Primary Energy|Coal'], diff --git a/tests/test_core.py b/tests/test_core.py index 7d11bfda4..359f0dcc2 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -521,10 +521,8 @@ def test_validate_up(meta_df): if 'year' in meta_df.data: assert obs['year'].values[0] == 2010 else: - assert ( - pd.to_datetime(obs['time'].values[0]) - == pd.to_datetime(datetime.datetime(2010, 7, 21)) - ) + exp_time = pd.to_datetime(datetime.datetime(2010, 7, 21)) + assert pd.to_datetime(obs['time'].values[0]) == exp_time assert list(meta_df['exclude']) == [False, False] # assert none excluded @@ -535,10 +533,9 @@ def test_validate_lo(meta_df): if 'year' in meta_df.data: assert obs['year'].values[0] == 2005 else: - assert ( - pd.to_datetime(obs['time'].values[0]) - == pd.to_datetime(datetime.datetime(2005, 6, 17)) - ) + exp_year = pd.to_datetime(datetime.datetime(2005, 6, 17)) + assert pd.to_datetime(obs['time'].values[0]) == exp_year + assert list(obs['scenario'].values) == ['scen_a'] @@ -548,13 +545,11 @@ def test_validate_both(meta_df): if 'year' in meta_df.data: assert list(obs['year'].values) == [2005, 2010] else: - assert ( - pd.to_datetime(obs['time'].values) - == pd.to_datetime([ - datetime.datetime(2005, 6, 17), - datetime.datetime(2010, 7, 21), - ]) - ).all() + exp_time = pd.to_datetime([ + datetime.datetime(2005, 6, 17), + datetime.datetime(2010, 7, 21), + ]) + assert (pd.to_datetime(obs['time'].values) == exp_time).all() assert list(obs['scenario'].values) == ['scen_a', 'scen_b'] @@ -581,10 +576,8 @@ def test_validate_top_level(meta_df): if 'year' in meta_df.data: assert obs['year'].values[0] == 2010 else: - assert ( - pd.to_datetime(obs['time'].values[0]) - == pd.to_datetime(datetime.datetime(2010, 7, 21)) - ) + exp_time = pd.to_datetime(datetime.datetime(2010, 7, 21)) + assert (pd.to_datetime(obs['time'].values[0]) == exp_time) assert list(meta_df['exclude']) == [False, True] @@ -1032,4 +1025,4 @@ def test_swap_time_to_year(test_df, inplace): assert compare(test_df, exp).empty else: assert compare(obs, exp).empty - assert not "year" in test_df.data.columns + assert "year" not in test_df.data.columns diff --git a/tests/test_feature_compare.py b/tests/test_feature_compare.py index 96a646808..7e6a11f77 100644 --- a/tests/test_feature_compare.py +++ b/tests/test_feature_compare.py @@ -4,7 +4,7 @@ import numpy as np import pandas as pd -from pyam import compare, IamDataFrame, IAMC_IDX +from pyam import compare, IAMC_IDX def test_compare(meta_df):