def test_metric_kwargs(self, metric):
        """Tests backtest with different metric_kwargs based on historical forecasts generated on a sequence
        `series` with last_points_only=False"""
        y = lt(length=20)
        y = y.stack(y + 1.0)
        hfc = lt(length=10, start=y.start_time() + 10 * y.freq)
        hfc = hfc.stack(hfc + 1.0)
        y = [y, y]
        hfc = [[hfc, hfc], [hfc]]

        metric_kwargs = [{"component_reduction": np.median}]
        if len(metric) > 1:
            # give metric specific kwargs
            metric_kwargs.append({
                "component_reduction": np.median,
                "time_reduction": np.mean,
            })

        model = NaiveDrift()
        # backtest should fail with invalid metric kwargs (mae does not support time reduction)
        with pytest.raises(TypeError) as err:
            _ = model.backtest(
                series=y,
                historical_forecasts=hfc,
                metric=metric,
                last_points_only=False,
                reduction=None,
                metric_kwargs={
                    "component_reduction": np.median,
                    "time_reduction": np.mean,
                },
            )
        assert str(err.value).endswith("unexpected keyword argument 'time_reduction'")

        bts = model.backtest(
            series=y,
            historical_forecasts=hfc,
            metric=metric,
            last_points_only=False,
            reduction=None,
            metric_kwargs=metric_kwargs,
        )
        assert isinstance(bts, list) and len(bts) == 2

        # `ae` with time and component reduction is equal to `mae` with component reduction
        bt_expected = metrics.mae(y[0], hfc[0][0], component_reduction=np.median)
        for bt_list in bts:
            for bt in bt_list:
                np.testing.assert_array_almost_equal(bt, bt_expected)

        def time_reduced_metric(*args, **kwargs):
            return metrics.ae(*args, **kwargs, time_reduction=np.mean)

        # check that single kwargs can be used for all metrics if params are supported
        metric = [metric[0], time_reduced_metric]
        bts = model.backtest(
            series=y,
            historical_forecasts=hfc,
            metric=metric,
            last_points_only=False,
            reduction=None,
            metric_kwargs=metric_kwargs[0],
        )
        assert isinstance(bts, list) and len(bts) == 2

        # `ae` with time and component reduction is equal to `mae` with component reduction
        bt_expected = metrics.mae(y[0], hfc[0][0], component_reduction=np.median)
        for bt_list in bts:
            for bt in bt_list:
                np.testing.assert_array_almost_equal(bt, bt_expected)
Tests backtest with different metric_kwargs based on historical forecasts generated on a sequence
        `series` with last_points_only=False
darts/tests/models/forecasting/test_backtesting.py