Skip to content

Commit

Permalink
Appease stickler
Browse files Browse the repository at this point in the history
  • Loading branch information
znicholls committed May 14, 2019
1 parent 363b584 commit 593729d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pyam/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions tests/test_cast_to_iamc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
27 changes: 11 additions & 16 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,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']


Expand All @@ -548,13 +547,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']

Expand All @@ -581,10 +578,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]


Expand Down Expand Up @@ -1032,4 +1027,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
2 changes: 1 addition & 1 deletion tests/test_feature_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 593729d

Please sign in to comment.