From 8217f6ee5e975f84e59709f5d220a4949e6a7dc0 Mon Sep 17 00:00:00 2001 From: Lea Braschi Date: Thu, 14 Nov 2024 06:45:27 -0400 Subject: [PATCH 1/4] add numpy>= 2.0 to build-requirements.py and setup.cfg --- build-requirements.txt | 2 +- setup.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build-requirements.txt b/build-requirements.txt index 646c4aa..3203b01 100644 --- a/build-requirements.txt +++ b/build-requirements.txt @@ -1,5 +1,5 @@ cython>=0.29 -numpy>=1.24 +numpy>=2.0 pandas>=2.0 pytest>=7 pytest-cov>=2.10 diff --git a/setup.cfg b/setup.cfg index 2b0d663..7ff5b3f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -41,7 +41,7 @@ requires = ["cython", "numpy", "scipy"] python_requires = >= 3.8 include_package_data = true install_requires = - numpy >= 1.20 + numpy >= 2.0 pandas >= 1.1 scikit-learn >= 0.23 scipy >= 1.5 From 9d52c32682bd64a3fa8104fa6e5c7f2c91174032 Mon Sep 17 00:00:00 2001 From: Lea Braschi Date: Thu, 14 Nov 2024 06:45:57 -0400 Subject: [PATCH 2/4] change np.float_ to np.float64 in frank.py --- copulae/archimedean/frank.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/copulae/archimedean/frank.py b/copulae/archimedean/frank.py index 83a6a02..7023ad2 100644 --- a/copulae/archimedean/frank.py +++ b/copulae/archimedean/frank.py @@ -237,7 +237,7 @@ def debye1(x): -------- :code:`copulae.special.debye.debye_1`: The debye order 1 function """ - x = np.asarray(x, np.float_).ravel() + x = np.asarray(x, np.float64).ravel() fin = np.isfinite(x) d = np.ravel(np.abs(x)) @@ -275,7 +275,7 @@ def debye2(x): -------- :code:`copulae.special.debye.debye_2`: The debye order 2 function """ - x = np.asarray(x, np.float_).ravel() + x = np.asarray(x, np.float64).ravel() fin = np.isfinite(x) d = np.ravel(np.abs(x)) From ec4db72ccc494535d78e421e69260e00bbba6ec5 Mon Sep 17 00:00:00 2001 From: Lea Braschi Date: Thu, 14 Nov 2024 06:48:28 -0400 Subject: [PATCH 3/4] change 'long' dtype to 'int64_t' in *.pyx files --- copulae/gof/_exchangeability.pyx | 2 +- copulae/gof/_radial_symmetry.pyx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/copulae/gof/_exchangeability.pyx b/copulae/gof/_exchangeability.pyx index be7c4b2..f3f81eb 100644 --- a/copulae/gof/_exchangeability.pyx +++ b/copulae/gof/_exchangeability.pyx @@ -209,7 +209,7 @@ def exch_test_stat(double[:, :] u, double[:, :] g, int n, int m): return s * n / m -def exch_replication(long[:, :] ir, double[:, :] u, double[:, :] g, int n, int m, int ng): +def exch_replication(int64_t[:, :] ir, double[:, :] u, double[:, :] g, int n, int m, int ng): """ One instance of the bootstrap replication diff --git a/copulae/gof/_radial_symmetry.pyx b/copulae/gof/_radial_symmetry.pyx index 35fe77f..c11f9cc 100644 --- a/copulae/gof/_radial_symmetry.pyx +++ b/copulae/gof/_radial_symmetry.pyx @@ -37,7 +37,7 @@ def rad_sym_test_stat(const double[:] u, const int n, const int p): return s -def rad_sym_replicate(double[:, :] u, long[:, :] ir, const int n, const int p, bint has_ties): +def rad_sym_replicate(double[:, :] u, int64_t[:, :] ir, const int n, const int p, bint has_ties): """One instance of bootstrap replication for radial symmetry test""" cdef: double[:, :] ub = np.copy(u), tub From c870825ae00948b288154c8c079f2e6f4b9bc17f Mon Sep 17 00:00:00 2001 From: Lea Braschi Date: Thu, 14 Nov 2024 08:03:02 -0400 Subject: [PATCH 4/4] address depreciation (numpy1.25): conversion of an array with ndim > 0 to a scalar --- copulae/archimedean/clayton.py | 5 ++++- copulae/archimedean/frank.py | 5 ++++- copulae/archimedean/gumbel.py | 10 ++++++++-- copulae/utility/annotations/reshape.py | 6 +++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/copulae/archimedean/clayton.py b/copulae/archimedean/clayton.py index 4e6d950..64d95e4 100644 --- a/copulae/archimedean/clayton.py +++ b/copulae/archimedean/clayton.py @@ -96,7 +96,10 @@ def params(self): @params.setter def params(self, theta: float): - theta = float(theta) + if np.isscalar(theta): + theta = float(theta) + elif isinstance(theta, np.ndarray) and theta.size == 1: + theta = float(theta.item()) if self.dim == 2 and theta < -1: raise ValueError('theta must be greater than -1 in 2 dimensional Clayton copula') diff --git a/copulae/archimedean/frank.py b/copulae/archimedean/frank.py index 7023ad2..392d617 100644 --- a/copulae/archimedean/frank.py +++ b/copulae/archimedean/frank.py @@ -123,7 +123,10 @@ def params(self): def params(self, theta): if self.dim > 2 and theta < 0: raise ValueError('theta must be positive when dim > 2') - self._theta = float(theta) + if np.isscalar(theta): + self._theta = float(theta) + elif isinstance(theta, np.ndarray) and theta.size == 1: + self._theta = float(theta.item()) @validate_data_dim({"u": [1, 2]}) @shape_first_input_to_cop_dim diff --git a/copulae/archimedean/gumbel.py b/copulae/archimedean/gumbel.py index c38cbfa..49f03c8 100644 --- a/copulae/archimedean/gumbel.py +++ b/copulae/archimedean/gumbel.py @@ -156,7 +156,10 @@ def ipsi(self, u: Array, log=False): def itau(self, tau): warning_message = "For the Gumbel copula, tau must be >= 0. Replacing negative values by 0." if np.size(tau) == 1: - tau = float(tau) + if np.isscalar(tau): + tau = float(tau) + elif isinstance(tau, np.ndarray) and tau.size == 1: + tau = float(tau.item()) if tau < 0: warnings.warn(warning_message) return 1 @@ -175,7 +178,10 @@ def params(self): @params.setter def params(self, theta: float): - theta = float(theta) + if np.isscalar(theta): + theta = float(theta) + elif isinstance(theta, np.ndarray) and theta.size == 1: + theta = float(theta.item()) if theta < 1: raise ValueError(' must be >= 1 for Gumbel copula') diff --git a/copulae/utility/annotations/reshape.py b/copulae/utility/annotations/reshape.py index 7b7db12..4c48278 100644 --- a/copulae/utility/annotations/reshape.py +++ b/copulae/utility/annotations/reshape.py @@ -101,4 +101,8 @@ def shape_first_input_to_cop_dim(method, instance: BaseCopula, args, kwargs): def squeeze_output(method, _, args, kwargs) -> Union[np.ndarray, pd.Series, float]: """Squeezes the output to a float if the size is one""" output: Union[float, np.ndarray, pd.Series] = method(*args, **kwargs) - return float(output) if np.isscalar(output) or output.size == 1 else output + if np.isscalar(output): + return float(output) + elif isinstance(output, np.ndarray) and output.size == 1: + return float(output.item()) + return output \ No newline at end of file