diff --git a/pyleoclim/core/multipleseries.py b/pyleoclim/core/multipleseries.py index 21c5e7a2..04925cab 100644 --- a/pyleoclim/core/multipleseries.py +++ b/pyleoclim/core/multipleseries.py @@ -1057,8 +1057,11 @@ def pca(self,weights=None, name=None, missing='fill-em',tol_em=5e-03, max_em_ite ''' flag, lengths = self.equal_lengths() - if flag==False: - print('All Time Series should be of same length. Apply common_time() first') + if flag == False: + raise ValueError( + "All series must be of the same length to perform PCA; " + f"got lengths {lengths}. Apply common_time() first." + ) else: # if all series have equal length p = len(lengths) n = lengths[0] diff --git a/pyleoclim/tests/test_core_MultipleSeries.py b/pyleoclim/tests/test_core_MultipleSeries.py index e319ed29..7f92d135 100644 --- a/pyleoclim/tests/test_core_MultipleSeries.py +++ b/pyleoclim/tests/test_core_MultipleSeries.py @@ -313,6 +313,19 @@ def test_pca_t3(self, gen_ts): # check that all variance was recovered assert abs(res.pctvar.sum() - 100) < 0.001 + def test_pca_t4(self, gen_ts): + """ + Series of unequal length must raise, not return None + + """ + signal = gen_ts(model="colored_noise", nt=100, alpha=1.0).standardize() + long = pyleo.Series(time=np.arange(100), value=signal.value) + short = pyleo.Series(time=np.arange(80), value=signal.value[:80]) + ms = pyleo.MultipleSeries([long, short]) + + with pytest.raises(ValueError, match="common_time"): + ms.pca() + class TestMultipleSeriesIncrements: """Test for MultipleSeries.increments()"""