Skip to content

Commit

Permalink
array checking for difference when inputs valid
Browse files Browse the repository at this point in the history
  • Loading branch information
AFg6K7h4fhy2 committed Nov 19, 2024
1 parent 8953228 commit 3ce31e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions forecasttools/idata_w_dates_to_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def generate_time_range_for_dim(

# get the size of the dimension
interval_size = variable_data.sizes[dimension]

# number of seconds in a day
SECONDS_IN_DAY = timedelta(days=1).total_seconds()

Expand Down
19 changes: 10 additions & 9 deletions tests/test_add_time_coords_to_idata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from datetime import datetime, timedelta

import numpy as np
import polars as pl
import pytest

Expand Down Expand Up @@ -109,15 +110,15 @@ def test_start_date_as_str_or_datetime(start_date_iso, time_step):
"posterior_predictive",
"obs",
"obs_dim_0",
timedelta(days=1),
timedelta(days=2), # fail when 1?
None,
), # valid
(
IDATA_WO_DATES,
"observed_data",
"obs",
"obs_dim_0",
timedelta(days=2),
timedelta(days=1),
None,
), # different valid
# invalid idata
Expand Down Expand Up @@ -239,24 +240,24 @@ def test_input_types_add_coords(
else:
# if no error is expected,
# execute the function
idata_out = forecasttools.add_time_coords_to_idata_dimension(
old_dim = idata[group][variable][dimension].values
idata = forecasttools.add_time_coords_to_idata_dimension(
idata=idata,
group=group,
variable=variable,
dimension=dimension,
start_date_iso="2022-08-01",
time_step=time_step,
)
new_dim = idata[group][variable][dimension].values
assert not np.array_equal(old_dim, new_dim)
# validate that the function executed
# correctly and the dimension has been modified
assert dimension in idata_out.posterior_predictive[variable].coords
assert dimension in idata.posterior_predictive[variable].coords
assert (
len(idata_out.posterior_predictive[variable].coords[dimension])
== idata_out.posterior_predictive[variable].sizes[dimension]
len(idata.posterior_predictive[variable].coords[dimension])
== idata.posterior_predictive[variable].sizes[dimension]
)
# old_dim = idata[group][variable][dimension]
# new_dim = idata_out[group][variable][dimension]
# assert not np.array_equal(old_dim, new_dim)


@pytest.mark.parametrize(
Expand Down

0 comments on commit 3ce31e8

Please sign in to comment.