Skip to content

Commit 2de1394

Browse files
TST: cover weight validation error paths in cov
Adds tests for the 1-D shape and length checks in the generic cov path. Raises the diff coverage for this PR from 93.33% to 100%.
1 parent e5f5d6a commit 2de1394

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

tests/test_funcs.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,23 @@ def test_axis_out_of_bounds(self, xp: ModuleType):
723723
with pytest.raises(IndexError):
724724
_ = cov(m, axis=5)
725725

726+
def test_weights_wrong_ndim(self, xp: ModuleType):
727+
m = xp.asarray([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
728+
w2d = xp.asarray([[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]])
729+
# Non-integer correction forces the generic path where the
730+
# validation lives; native backends raise for the same reason.
731+
with pytest.raises((ValueError, TypeError)):
732+
_ = cov(m, correction=0.5, fweights=w2d)
733+
with pytest.raises((ValueError, TypeError)):
734+
_ = cov(m, correction=0.5, aweights=w2d)
735+
736+
def test_weights_wrong_length(self, xp: ModuleType):
737+
m = xp.asarray([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
738+
w_bad = xp.asarray([1.0, 1.0]) # expected length 3
739+
with pytest.raises((ValueError, RuntimeError)):
740+
_ = cov(m, correction=0.5, fweights=w_bad)
741+
with pytest.raises((ValueError, RuntimeError)):
742+
_ = cov(m, correction=0.5, aweights=w_bad)
726743

727744

728745
@pytest.mark.xfail_xp_backend(Backend.SPARSE, reason="no arange", strict=False)

0 commit comments

Comments
 (0)