diff --git a/.github/workflows/tests-torch.yml b/.github/workflows/tests-torch.yml index 3763f6f01f..fde0bf221f 100644 --- a/.github/workflows/tests-torch.yml +++ b/.github/workflows/tests-torch.yml @@ -24,8 +24,8 @@ jobs: pip install ".[arrow]" \ -r requirements/requirements-test.txt \ -r requirements/requirements-extras-m-competitions.txt \ - -r requirements/requirements-pytorch.txt \ - -r requirements/requirements-extras-cpflows.txt + -r requirements/requirements-pytorch.txt + pip install --no-deps -r requirements/requirements-extras-cpflows.txt - name: Test with pytest run: | pytest -n2 --doctest-modules --ignore test/nursery test diff --git a/requirements/requirements-pytorch.txt b/requirements/requirements-pytorch.txt index e3e9432c0d..6e26f8cd4c 100644 --- a/requirements/requirements-pytorch.txt +++ b/requirements/requirements-pytorch.txt @@ -1,6 +1,6 @@ torch>=1.9,<3 -lightning>=2.2.2,<2.4 +lightning>=2.2.2,<2.5 # Capping `lightning` does not cap `pytorch_lightning`, so we cap manually -pytorch_lightning>=2.2.2,<2.4 +pytorch_lightning>=2.2.2,<2.5 scipy~=1.10; python_version > "3.7.0" scipy~=1.7.3; python_version <= "3.7.0" diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 49df084e85..acc7f18fcd 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,4 +1,4 @@ -numpy~=1.16 +numpy>=1.16,<2.2 pandas>=1.0,<3 pydantic>=1.7,<3 tqdm~=4.23 diff --git a/src/gluonts/dataset/pandas.py b/src/gluonts/dataset/pandas.py index dcdb1d5456..bb86055cab 100644 --- a/src/gluonts/dataset/pandas.py +++ b/src/gluonts/dataset/pandas.py @@ -15,7 +15,7 @@ import logging from dataclasses import dataclass, field, InitVar -from typing import Any, Iterable, Optional, Type, Union, cast +from typing import Any, Iterable, Optional, Type, Union import numpy as np import pandas as pd @@ -351,4 +351,4 @@ def is_uniform(index: pd.PeriodIndex) -> bool: False """ - return cast(bool, np.all(np.diff(index.asi8) == index.freq.n)) + return bool(np.all(np.diff(index.asi8) == index.freq.n)) diff --git a/src/gluonts/itertools.py b/src/gluonts/itertools.py index db9587c735..44398e5eb6 100644 --- a/src/gluonts/itertools.py +++ b/src/gluonts/itertools.py @@ -240,7 +240,7 @@ def _location_for(self, idx, side="right") -> _SubIndex: else: local_idx = idx - self._offsets[part_no - 1] - return _SubIndex(part_no, local_idx) + return _SubIndex(int(part_no), int(local_idx)) def __getitem__(self, idx): if isinstance(idx, slice): diff --git a/src/gluonts/model/forecast_generator.py b/src/gluonts/model/forecast_generator.py index 0148a8e1e6..d3207c5f23 100644 --- a/src/gluonts/model/forecast_generator.py +++ b/src/gluonts/model/forecast_generator.py @@ -59,7 +59,7 @@ def _unpack(batched) -> Iterator: This assumes that arrays are wrapped in a nested structure of lists and tuples, and each array has the same shape:: - >>> a = np.arange(5) + >>> a = np.arange(5, dtype="O") >>> batched = [a, (a, [a, a, a])] >>> list(_unpack(batched)) [[0, (0, [0, 0, 0])], diff --git a/src/gluonts/mx/trainer/_base.py b/src/gluonts/mx/trainer/_base.py index 8eaec8651e..8b1dda9ad7 100644 --- a/src/gluonts/mx/trainer/_base.py +++ b/src/gluonts/mx/trainer/_base.py @@ -227,7 +227,7 @@ def base_path() -> str: best_epoch_info = { "params_path": "{}-{}.params".format(base_path(), "init"), "epoch_no": -1, - "score": np.Inf, + "score": float("inf"), } optimizer = mx.optimizer.Adam( diff --git a/src/gluonts/mx/trainer/learning_rate_scheduler.py b/src/gluonts/mx/trainer/learning_rate_scheduler.py index e550d1d0cf..5f33445b1e 100644 --- a/src/gluonts/mx/trainer/learning_rate_scheduler.py +++ b/src/gluonts/mx/trainer/learning_rate_scheduler.py @@ -50,7 +50,7 @@ def should_update(self, metric: float) -> bool: @dataclass class Min(Objective): - best: float = np.Inf + best: float = float("inf") def should_update(self, metric: float) -> bool: return metric < self.best @@ -58,7 +58,7 @@ def should_update(self, metric: float) -> bool: @dataclass class Max(Objective): - best: float = -np.Inf + best: float = -float("inf") def should_update(self, metric: float) -> bool: return metric > self.best diff --git a/test/torch/distribution/test_negative_binomial.py b/test/torch/distribution/test_negative_binomial.py index 26abe8fcaa..7e80019e4e 100644 --- a/test/torch/distribution/test_negative_binomial.py +++ b/test/torch/distribution/test_negative_binomial.py @@ -12,6 +12,7 @@ # permissions and limitations under the License. import pytest +import sys import numpy as np import torch @@ -49,11 +50,13 @@ def test_custom_neg_bin_cdf(total_count, probs, value): @pytest.mark.parametrize("probs", [0.1, 0.5, 0.8]) @pytest.mark.parametrize("total_count", [3, 7, 100]) @pytest.mark.parametrize("value", [0.1, 0.5, 0.9]) -def test_custom_studentt_icdf(total_count, probs, value): +def test_custom_neg_bin_icdf(total_count, probs, value): torch_dist = NegativeBinomial(total_count=total_count, probs=probs) scipy_dist = torch_dist.scipy_nbinom - torch_icdf = torch_dist.icdf(torch.as_tensor(value)).numpy() + torch_icdf = torch_dist.icdf( + torch.as_tensor(value, dtype=torch.float64) + ).numpy() scipy_icdf = scipy_dist.ppf(np.asarray(value)) assert np.allclose(torch_icdf, scipy_icdf) diff --git a/test/transform/test_transform.py b/test/transform/test_transform.py index fbcdfb9d16..bc9815427c 100644 --- a/test/transform/test_transform.py +++ b/test/transform/test_transform.py @@ -155,8 +155,8 @@ def test_AddTimeFeatures(start, target, is_train: bool): tmp_idx = pd.period_range( start=start, freq=start.freq, periods=expected_length ) - assert np.alltrue(mat[0] == time_feature.day_of_week(tmp_idx)) - assert np.alltrue(mat[1] == time_feature.day_of_month(tmp_idx)) + assert np.all(mat[0] == time_feature.day_of_week(tmp_idx)) + assert np.all(mat[1] == time_feature.day_of_month(tmp_idx)) @pytest.mark.parametrize("is_train", TEST_VALUES["is_train"]) @@ -285,7 +285,7 @@ def test_InstanceSplitter( # expected_length = len(target) + (0 if is_train else pred_length) # assert len(out['age']) == expected_length - # assert np.alltrue(out['age'] == np.log10(2.0 + np.arange(expected_length))) + # assert np.all(out['age'] == np.log10(2.0 + np.arange(expected_length))) @pytest.mark.parametrize("is_train", TEST_VALUES["is_train"])