From 28424e318cc7ebf2585894c497f99904ec75bf81 Mon Sep 17 00:00:00 2001 From: dennisbader Date: Mon, 6 Nov 2023 11:05:19 +0100 Subject: [PATCH] apply suggestions from PR review --- darts/dataprocessing/encoders/encoders.py | 2 +- darts/tests/utils/test_timeseries_generation.py | 13 ++++++++++--- darts/utils/timeseries_generation.py | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/darts/dataprocessing/encoders/encoders.py b/darts/dataprocessing/encoders/encoders.py index 912e00ef43..09b3414593 100644 --- a/darts/dataprocessing/encoders/encoders.py +++ b/darts/dataprocessing/encoders/encoders.py @@ -884,7 +884,7 @@ def __init__( BoxCox(). The transformers will be fitted on the training dataset when calling calling `model.fit()`. The training, validation and inference datasets are then transformed equally. Supported time zone: - optionally, apply a time zone conversion with keyword 'tz'. This converts the time zone-naive index to a + Optionally, apply a time zone conversion with keyword 'tz'. This converts the time zone-naive index to a timezone `'tz'` before applying the `'cyclic'` or `'datetime_attribute'` temporal encoders. An example of a valid `add_encoders` dict for hourly data: diff --git a/darts/tests/utils/test_timeseries_generation.py b/darts/tests/utils/test_timeseries_generation.py index 5d2f7e963c..606e36d311 100644 --- a/darts/tests/utils/test_timeseries_generation.py +++ b/darts/tests/utils/test_timeseries_generation.py @@ -358,18 +358,25 @@ def helper_routine(idx, attr, vals_exp, **kwargs): np.testing.assert_array_almost_equal(vals_act, vals_exp) # no pd.DatetimeIndex - with pytest.raises(ValueError): + with pytest.raises(ValueError) as err: helper_routine( pd.RangeIndex(start=0, stop=len(idx)), "h", vals_exp=np.arange(len(idx)) ) + assert str(err.value).startswith( + "`time_index` must be a pandas `DatetimeIndex`" + ) # invalid attribute - with pytest.raises(ValueError): + with pytest.raises(ValueError) as err: helper_routine(idx, "h", vals_exp=np.arange(len(idx))) + assert str(err.value).startswith( + "attribute `h` needs to be an attribute of pd.DatetimeIndex." + ) # no time zone aware index - with pytest.raises(ValueError): + with pytest.raises(ValueError) as err: helper_routine(idx.tz_localize("UTC"), "h", vals_exp=np.arange(len(idx))) + assert "`time_index` must be time zone naive." == str(err.value) # ===> datetime attribute # hour diff --git a/darts/utils/timeseries_generation.py b/darts/utils/timeseries_generation.py index d09744d99a..da1d2a524c 100644 --- a/darts/utils/timeseries_generation.py +++ b/darts/utils/timeseries_generation.py @@ -547,7 +547,7 @@ def holidays_timeseries( Parameters ---------- time_index - Either a `pd.DatetimeIndex` or a `TimeSeries` for which to generate the holidays/ + Either a `pd.DatetimeIndex` or a `TimeSeries` for which to generate the holidays. country_code The country ISO code. prov @@ -561,7 +561,7 @@ def holidays_timeseries( Extend the time_index by add_length, should match or exceed forecasting window. Set only one of until and add_length. column_name - Optionally, the name of the value column for the returned TimeSeries/ + Optionally, the name of the value column for the returned TimeSeries. dtype The desired NumPy dtype (np.float32 or np.float64) for the resulting series. tz