Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pyleoclim/core/multipleseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 13 additions & 0 deletions pyleoclim/tests/test_core_MultipleSeries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()"""
Expand Down