From 4a03bae1363698333a259d72dfec563c49a8c9a0 Mon Sep 17 00:00:00 2001 From: Julien Emile-Geay Date: Fri, 3 Mar 2023 12:39:45 -0800 Subject: [PATCH] added segment number to labels (#356) * added segment number to labels * added test for segment labels --- pyleoclim/core/series.py | 7 ++++++- pyleoclim/tests/test_core_Series.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pyleoclim/core/series.py b/pyleoclim/core/series.py index 56fc8ec6..45c16729 100644 --- a/pyleoclim/core/series.py +++ b/pyleoclim/core/series.py @@ -2369,9 +2369,13 @@ def segment(self, factor=10): if len(seg_y)>1: s_list=[] for idx,s in enumerate(seg_y): + if self.label is not None: + s_lbl = self.label + ' segment ' + str(idx+1) + else: + s_lbl = 'segment ' + str(idx+1) s_tmp=Series(time=seg_t[idx],value=s,time_name=self.time_name, time_unit=self.time_unit, value_name=self.value_name, - value_unit=self.value_unit,label=self.label) + value_unit=self.value_unit,label=s_lbl) s_list.append(s_tmp) res=MultipleSeries(series_list=s_list) elif len(seg_y)==1: @@ -2380,6 +2384,7 @@ def segment(self, factor=10): raise ValueError('No timeseries detected') return res + def sel(self, value=None, time=None, tolerance=0): """ Slice Series based on 'value' or 'time'. diff --git a/pyleoclim/tests/test_core_Series.py b/pyleoclim/tests/test_core_Series.py index 582b3d65..82ec80eb 100644 --- a/pyleoclim/tests/test_core_Series.py +++ b/pyleoclim/tests/test_core_Series.py @@ -430,6 +430,17 @@ def test_segment_t1(self): ts_seg = ts.segment() assert type(ts_seg) == type(ts) + + def test_segment_t2(self): + '''Test that in the case of segmentation, segment returns a Multiple Series object''' + t = (1,2,3000) + v = (1,2,3) + + ts = pyleo.Series(time = t, value = v, label = 'series') + + ts_seg = ts.segment() + + assert ts_seg.series_list[0].label == 'series segment 1' class TestUiSeriesSlice: '''Test for Series.slice()