diff --git a/pyerrors/obs.py b/pyerrors/obs.py index a806c597..6889fd3f 100644 --- a/pyerrors/obs.py +++ b/pyerrors/obs.py @@ -1356,7 +1356,7 @@ def covariance(obs, visualize=False, correlation=False, **kwargs): length = len(obs) max_samples = np.max([o.N for o in obs]) - if max_samples <= length: + if max_samples <= length and not [item for sublist in [o.cov_names for o in obs] for item in sublist]: warnings.warn(f"The dimension of the covariance matrix ({length}) is larger or equal to the number of samples ({max_samples}). This will result in a rank deficient matrix.", RuntimeWarning) cov = np.zeros((length, length)) diff --git a/tests/obs_test.py b/tests/obs_test.py index 3d773951..a2f40fdf 100644 --- a/tests/obs_test.py +++ b/tests/obs_test.py @@ -696,6 +696,15 @@ def test_covariance_correlation(): assert np.allclose(pe.covariance([test_obs, test_obs, test_obs], correlation=True), np.ones((3, 3))) +def test_covariance_rank_deficient(): + obs = [] + for i in range(5): + obs.append(pe.pseudo_Obs(1.0, 0.1, 'test', 5)) + + with pytest.warns(RuntimeWarning): + pe.covariance(obs) + + def test_empty_obs(): o = pe.Obs([np.random.rand(100)], ['test']) q = o + pe.Obs([], [])