Skip to content

Commit

Permalink
fix: tests properly account for static covariates representation depe…
Browse files Browse the repository at this point in the history
…nding on the number of components
  • Loading branch information
madtoinou committed Jul 17, 2023
1 parent 1290d9f commit 6b055d6
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions darts/tests/dataprocessing/transformers/test_midas.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,13 @@ def test_multiple_ts(self):
)

def test_ts_with_static_covariates(self):
# univarite ts, "global" static covariates
# univarite ts, same number of static covariates as components
global_static_covs = pd.Series(data=[0, 1], index=["static_0", "static_1"])
monthly_with_static_covs = self.monthly_ts.with_static_covariates(
global_static_covs
)

# multivariate ts, component-specific static covariates
# multivariate ts, different number of static covariates than components
components_static_covs = pd.DataFrame(
data=[["low", 1, 9], ["high", 0, 2]],
columns=["static_2", "static_3", "static_4"],
Expand All @@ -368,7 +368,7 @@ def test_ts_with_static_covariates(self):

# dropping the static covariates
midas_drop_static_covs = MIDAS(low_freq="QS", drop_static_covariates=True)
# testing univariate (no/global static covariates), multivariate (component-wise static covariates)
# testing univariate (with/without static covariates), multivariate with static covariates
for ts in [
self.monthly_ts,
monthly_with_static_covs,
Expand All @@ -389,24 +389,31 @@ def test_ts_with_static_covariates(self):
)
self.assertTrue(inv_quartely_no_static.static_covariates is None)

# univariate, with global static covariates : transform does not change static covariates
expected_static_covs = monthly_with_static_covs.static_covariates
# univariate, with static covariates
expected_static_covs = pd.concat(
[monthly_with_static_covs.static_covariates] * 3
)
expected_static_covs.index = [
"values_0",
"values_1",
"values_2",
]
quartely_univ_dropped_static = midas_with_static_covs.fit_transform(
monthly_with_static_covs
)
self.assertTrue(
quartely_univ_dropped_static.static_covariates.equals(expected_static_covs)
quartely_univ_dropped_static.static_covariates.equals(expected_static_covs),
)
inv_quartely_univ_dropped_static = midas_with_static_covs.inverse_transform(
quartely_univ_dropped_static
)
self.assertTrue(
inv_quartely_univ_dropped_static.static_covariates.equals(
expected_static_covs
monthly_with_static_covs.static_covariates
)
)

# testing multivariate, component-wise static covariates : covariates are duplicated for each new component
# testing multivariate, with static covariates
expected_static_covs = pd.concat(
[monthly_multivar_with_static_covs.static_covariates] * 3
)
Expand Down

0 comments on commit 6b055d6

Please sign in to comment.