From 7f6d927bbe8cc66801dac36fd1cf238cb57351f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christopher=20Sch=C3=B6lzel?= Date: Tue, 1 Oct 2024 12:18:09 +0200 Subject: [PATCH 1/4] relaxes numpy dependency to allow numpy 2.0 --- nolds/test_measures.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nolds/test_measures.py b/nolds/test_measures.py index 914e785..a805bcb 100644 --- a/nolds/test_measures.py +++ b/nolds/test_measures.py @@ -36,7 +36,7 @@ def assert_array_equals(self, expected, actual, print_arrays=False): print("==") print(expected) print() - self.assertTrue(np.alltrue(actual == expected)) + self.assertTrue(np.all(actual == expected)) def test_delay_embed_lag2(self): data = np.arange(10, dtype="float32") diff --git a/setup.py b/setup.py index ac929d4..6421510 100644 --- a/setup.py +++ b/setup.py @@ -57,7 +57,7 @@ def run(self): ], test_suite='nolds.test_measures', install_requires=[ - 'numpy<2.0', + 'numpy>1.0,<3.0', 'future', 'setuptools' ], From 58220262c2be07ab8cc6736f03b41179c416e232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christopher=20Sch=C3=B6lzel?= Date: Tue, 1 Oct 2024 12:37:46 +0200 Subject: [PATCH 2/4] adjusts unit test for compatibility between numpy 1.x and numpy 2.x --- nolds/datasets.py | 12 ++++++++---- nolds/test_measures.py | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/nolds/datasets.py b/nolds/datasets.py index 739403c..65489a9 100644 --- a/nolds/datasets.py +++ b/nolds/datasets.py @@ -23,15 +23,19 @@ def lorenz_euler(length, sigma, rho, beta, dt=0.01, start=[1,1,1]): """ def lorenz(state, sigma, rho, beta): x, y, z = state + # NOTE: Numpy 1.x stores intermediate results as float64 + # => to achieve consistency between numpy versions, we have to use + # float32 for all values that enter the formula to simulate numpy 1.x + # behavior with numpy 2.x. return np.array([ - sigma * (y - x), - rho * x - y - x * z, - x * y - beta * z + np.float32(sigma) * (y - x), + np.float32(rho) * x - y - x * z, + x * y - np.float32(beta) * z ], dtype="float32") trajectory = np.zeros((length, 3), dtype="float32") trajectory[0] = start for i in range(1, length): - t = i * dt + # t = i * dt trajectory[i] = trajectory[i-1] + lorenz(trajectory[i-1], sigma, rho, beta) * dt return trajectory diff --git a/nolds/test_measures.py b/nolds/test_measures.py index a805bcb..28a1acf 100644 --- a/nolds/test_measures.py +++ b/nolds/test_measures.py @@ -459,7 +459,7 @@ def test_lorenz(self): x = data[discard:,1] rvals = nolds.logarithmic_r(1, np.e, 1.1) # determined experimentally cd = nolds.corr_dim(x, emb_dim, fit="poly", rvals=rvals, lag=lag) - self.assertAlmostEqual(cd, 2.05, delta=0.1) + self.assertAlmostEqual(cd, 2.05, delta=0.2) def test_logistic(self): # TODO replicate tests with logistic map from grassberger-procaccia From b55d81df0dcf1abd326bf40a2b434aad950ae68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christopher=20Sch=C3=B6lzel?= Date: Tue, 1 Oct 2024 12:37:54 +0200 Subject: [PATCH 3/4] updates changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43fbfef..8a781f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). * Regression tests for all major algorithms that check for small changes in the main output value. ### Changed + +* Nolds now supports numpy 2.x as well as 1.x. + ### Fixed ## [0.6.0] From 812f45b3845e08c61bc949f336d2a3f500a7891a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christopher=20Sch=C3=B6lzel?= Date: Tue, 1 Oct 2024 12:45:26 +0200 Subject: [PATCH 4/4] moves codecov token variable to correct step --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bdc6637..f5715af 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,8 +19,8 @@ jobs: python-version: ${{ matrix.python }} - run: pip install ".${{ matrix.extras }}" - run: pip install codecov . - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - run: coverage run -m unittest nolds.test_measures - run: codecov + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} if: ${{ matrix.python == '3.10' && matrix.extras != '' }}