From 1c1b8ff2e1d58c76a6ca94a031a6b6d412f93553 Mon Sep 17 00:00:00 2001 From: Frances Hartwell Date: Mon, 22 Dec 2025 18:07:06 -0500 Subject: [PATCH 1/4] Fix cases using arrays instead of scalars --- copulas/bivariate/base.py | 2 +- copulas/bivariate/frank.py | 2 +- copulas/multivariate/tree.py | 4 ++-- copulas/multivariate/vine.py | 2 +- tests/unit/bivariate/test_base.py | 3 ++- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/copulas/bivariate/base.py b/copulas/bivariate/base.py index a12c7bef..7f5dc026 100644 --- a/copulas/bivariate/base.py +++ b/copulas/bivariate/base.py @@ -341,7 +341,7 @@ def partial_derivative_scalar(self, U, V): self.check_fit() X = np.column_stack((U, V)) - return self.partial_derivative(X) + return self.partial_derivative(X).item() def set_random_state(self, random_state): """Set the random state. diff --git a/copulas/bivariate/frank.py b/copulas/bivariate/frank.py index 76f29dd1..6879630a 100644 --- a/copulas/bivariate/frank.py +++ b/copulas/bivariate/frank.py @@ -166,5 +166,5 @@ def _tau_to_theta(self, alpha): def debye(t): return t / (np.exp(t) - 1) - debye_value = integrate.quad(debye, EPSILON, alpha)[0] / alpha + debye_value = integrate.quad(debye, EPSILON, alpha.item())[0] / alpha return 4 * (debye_value - 1) / alpha + 1 - self.tau diff --git a/copulas/multivariate/tree.py b/copulas/multivariate/tree.py index 0eea1d0e..bc939f6a 100644 --- a/copulas/multivariate/tree.py +++ b/copulas/multivariate/tree.py @@ -202,8 +202,8 @@ def get_likelihood(self, uni_matrix): for i in range(num_edge): edge = self.edges[i] value, left_u, right_u = edge.get_likelihood(uni_matrix) - new_uni_matrix[edge.L, edge.R] = left_u - new_uni_matrix[edge.R, edge.L] = right_u + new_uni_matrix[edge.L, edge.R] = left_u.item() + new_uni_matrix[edge.R, edge.L] = right_u.item() values[0, i] = np.log(value) return np.sum(values), new_uni_matrix diff --git a/copulas/multivariate/vine.py b/copulas/multivariate/vine.py index 2c786ad4..25bc7595 100644 --- a/copulas/multivariate/vine.py +++ b/copulas/multivariate/vine.py @@ -329,7 +329,7 @@ def _sample_row(self): new_x = self.ppfs[current](np.array([tmp])) - sampled[current] = new_x + sampled[current] = new_x.item() for s in neighbors: if s not in visited: diff --git a/tests/unit/bivariate/test_base.py b/tests/unit/bivariate/test_base.py index 6fb2a400..5b81e72a 100644 --- a/tests/unit/bivariate/test_base.py +++ b/tests/unit/bivariate/test_base.py @@ -105,12 +105,13 @@ def test_partial_derivative_scalar(self, derivative_mock): # Setup instance = Bivariate(copula_type=CopulaTypes.CLAYTON) instance.fit(self.X) + derivative_mock.return_value = np.array([1.0]) # Run result = instance.partial_derivative_scalar(0.5, 0.1) # Check - assert result == derivative_mock.return_value + assert result == 1.0 expected_args = ((np.array([[0.5, 0.1]]), 0), {}) assert len(expected_args) == len(derivative_mock.call_args) From dfc25f3c5704f1f7ccc13552bc1341e10b9ab2af Mon Sep 17 00:00:00 2001 From: Frances Hartwell Date: Tue, 23 Dec 2025 11:56:20 -0500 Subject: [PATCH 2/4] Update minimum tests to install minimum scikit-learn --- tasks.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tasks.py b/tasks.py index d2522cdf..73ba5db6 100644 --- a/tasks.py +++ b/tasks.py @@ -101,9 +101,10 @@ def _get_minimum_versions(dependencies, python_version): @task def install_minimum(c): with open('pyproject.toml', 'rb') as pyproject_file: - pyproject_data = tomli.load(pyproject_file) + pyproject_data = tomli.load(pyproject_file).get('project', {}) - dependencies = pyproject_data.get('project', {}).get('dependencies', []) + dependencies = pyproject_data.get('dependencies', []) + dependencies += pyproject_data.get('optional-dependencies', {}).get('tutorials', []) python_version = '.'.join(map(str, sys.version_info[:2])) minimum_versions = _get_minimum_versions(dependencies, python_version) From 998596e4eef73d9a5092a4d7a2866ad4f0efad0e Mon Sep 17 00:00:00 2001 From: Frances Hartwell Date: Tue, 23 Dec 2025 12:01:52 -0500 Subject: [PATCH 3/4] Install scikit-learn<1.8.0 for minimum tests --- .github/workflows/minimum.yml | 1 + tasks.py | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/minimum.yml b/.github/workflows/minimum.yml index c63fa6b1..78ccac53 100644 --- a/.github/workflows/minimum.yml +++ b/.github/workflows/minimum.yml @@ -31,5 +31,6 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install invoke .[test] + python -m pip install "scikit-learn<1.8.0" - name: Test with minimum versions run: invoke minimum diff --git a/tasks.py b/tasks.py index 73ba5db6..d2522cdf 100644 --- a/tasks.py +++ b/tasks.py @@ -101,10 +101,9 @@ def _get_minimum_versions(dependencies, python_version): @task def install_minimum(c): with open('pyproject.toml', 'rb') as pyproject_file: - pyproject_data = tomli.load(pyproject_file).get('project', {}) + pyproject_data = tomli.load(pyproject_file) - dependencies = pyproject_data.get('dependencies', []) - dependencies += pyproject_data.get('optional-dependencies', {}).get('tutorials', []) + dependencies = pyproject_data.get('project', {}).get('dependencies', []) python_version = '.'.join(map(str, sys.version_info[:2])) minimum_versions = _get_minimum_versions(dependencies, python_version) From a4a99691ca1048c00aebaeb3bd1429ab13dcbbef Mon Sep 17 00:00:00 2001 From: Frances Hartwell Date: Tue, 23 Dec 2025 13:00:13 -0500 Subject: [PATCH 4/4] Match SDV's handling of external minimum dependencies --- .github/workflows/minimum.yml | 1 - tasks.py | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/minimum.yml b/.github/workflows/minimum.yml index 78ccac53..c63fa6b1 100644 --- a/.github/workflows/minimum.yml +++ b/.github/workflows/minimum.yml @@ -31,6 +31,5 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install invoke .[test] - python -m pip install "scikit-learn<1.8.0" - name: Test with minimum versions run: invoke minimum diff --git a/tasks.py b/tasks.py index d2522cdf..353b0733 100644 --- a/tasks.py +++ b/tasks.py @@ -21,6 +21,9 @@ '<=': operator.le, '==': operator.eq, } +EXTERNAL_DEPENDENCY_CAPS = { + 'scikit-learn': '1.8.0' +} if not hasattr(inspect, 'getargspec'): @@ -110,6 +113,8 @@ def install_minimum(c): if minimum_versions: install_deps = ' '.join(minimum_versions) c.run(f'python -m pip install {install_deps}') + for dep, cap in EXTERNAL_DEPENDENCY_CAPS.items(): + c.run(f'python -m pip install "{dep}<{cap}"') @task