Skip to content

Commit

Permalink
Make ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhuppmann committed Dec 17, 2024
1 parent a623d5e commit a468544
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
16 changes: 9 additions & 7 deletions pyam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,15 @@ def print_list(x, n):

# utility method to compare years (as integer) and datetime for index-sorting
def compare_year_time(x):
return pd.Index([
# set year lower than first timestep of that year (2010 < 2010-01-01 00:00)
datetime(time, 1, 1, 0, 0, 0) - timedelta(0, 0.01)
if isinstance(time, int)
else time
for time in x
])
return pd.Index(
[
# set year lower than first timestep of that year (2010 < 2010-01-01 00:00)
datetime(time, 1, 1, 0, 0, 0) - timedelta(0, 0.01)
if isinstance(time, int)
else time
for time in x
]
)


def to_time(x):
Expand Down
15 changes: 6 additions & 9 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,8 @@ def test_timeseries_wide(test_pd_df, unsort):
def test_timeseries_mixed_time_domain(test_pd_df):
"""Assert that timeseries is shown as expected from mixed time-domain data"""
test_pd_df = test_pd_df.rename(columns={2005: "2010-01-01 00:00"})
exp = (
test_pd_df.set_index(IAMC_IDX)[[2010, "2010-01-01 00:00"]]
.rename(columns={"2010-01-01 00:00": datetime(2010, 1, 1, 0, 0)})
exp = test_pd_df.set_index(IAMC_IDX)[[2010, "2010-01-01 00:00"]].rename(
columns={"2010-01-01 00:00": datetime(2010, 1, 1, 0, 0)}
)

obs = IamDataFrame(test_pd_df).timeseries()
Expand Down Expand Up @@ -738,9 +737,7 @@ def test_normalize(test_df):
if "year" in test_df.data:
obs = test_df.normalize(year=2005).data.reset_index(drop=True)
else:
obs = test_df.normalize(time=datetime(2005, 6, 17)).data.reset_index(
drop=True
)
obs = test_df.normalize(time=datetime(2005, 6, 17)).data.reset_index(drop=True)
pdt.assert_frame_equal(obs, exp)


Expand All @@ -759,9 +756,9 @@ def test_offset(test_df, padding):
if "year" in test_df.data:
obs = test_df.offset(year=2005, **kwargs).data.reset_index(drop=True)
else:
obs = test_df.offset(
time=datetime(2005, 6, 17), **kwargs
).data.reset_index(drop=True)
obs = test_df.offset(time=datetime(2005, 6, 17), **kwargs).data.reset_index(
drop=True
)
pdt.assert_frame_equal(obs, exp)


Expand Down
1 change: 0 additions & 1 deletion tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,3 @@ def test_data_sort_mixed_time_domain(test_df_year, inplace):
else:
obs = df.sort_data()
pdt.assert_frame_equal(obs.data, mixed_data)

0 comments on commit a468544

Please sign in to comment.