From 9e96e512023e97c12eb35af86dbd662a9d893a7a Mon Sep 17 00:00:00 2001 From: Alexander James Date: Thu, 15 Jun 2023 15:51:00 -0700 Subject: [PATCH 1/5] add conftest series with nans --- pyleoclim/tests/conftest.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pyleoclim/tests/conftest.py b/pyleoclim/tests/conftest.py index caf36bba..f21937ea 100644 --- a/pyleoclim/tests/conftest.py +++ b/pyleoclim/tests/conftest.py @@ -43,6 +43,16 @@ def unevenly_spaced_series(): series = pyleo.Series(time=t, value =v, verbose=False) return series +@pytest.fixture +def unevenly_spaced_series_nans(): + """Pyleoclim series with unevenly spaced time axis""" + length = 10 + t = np.linspace(1,length,length) ** 2 + v = np.ones(length) + v[2:4] = np.nan + series = pyleo.Series(time=t, value =v, dropna=False, verbose=False) + return series + @pytest.fixture def evenly_spaced_series(): """Pyleoclim series with evenly spaced time axis""" From feb00408bb1d76e7128367857e8ed0f806e3f0c7 Mon Sep 17 00:00:00 2001 From: Alexander James Date: Thu, 15 Jun 2023 15:53:10 -0700 Subject: [PATCH 2/5] drop nans before computing res --- pyleoclim/core/series.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pyleoclim/core/series.py b/pyleoclim/core/series.py index 43f97883..553d273c 100644 --- a/pyleoclim/core/series.py +++ b/pyleoclim/core/series.py @@ -4017,8 +4017,12 @@ def resolution(self): resolution.dashboard() """ - - res,_,_ = tsbase.resolution(self.time) + x = self.time + + if any(np.isnan(x)): #Drop nans from x if they're present + x = x[~np.isnan(x)] + + res,_,_ = tsbase.resolution(x=x) resolution = Resolution( resolution = res, From baac4244bb93e50d33bd78ef305d215c61a394ed Mon Sep 17 00:00:00 2001 From: Alexander James Date: Thu, 15 Jun 2023 15:53:24 -0700 Subject: [PATCH 3/5] include median in resolution.describe --- pyleoclim/core/resolution.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyleoclim/core/resolution.py b/pyleoclim/core/resolution.py index 6c75c990..921364f5 100644 --- a/pyleoclim/core/resolution.py +++ b/pyleoclim/core/resolution.py @@ -79,6 +79,9 @@ def describe(self): ''' stats = st.describe(self.resolution)._asdict() + + median = np.median(self.resolution) + stats['median'] = median return stats From 9ab39340b178456f6ee5ab77593c9c2abf443372 Mon Sep 17 00:00:00 2001 From: Alexander James Date: Thu, 15 Jun 2023 16:20:15 -0700 Subject: [PATCH 4/5] improve resolution tests --- pyleoclim/tests/test_core_Resolution.py | 29 +++++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/pyleoclim/tests/test_core_Resolution.py b/pyleoclim/tests/test_core_Resolution.py index 0a9c0ad8..25777c6c 100644 --- a/pyleoclim/tests/test_core_Resolution.py +++ b/pyleoclim/tests/test_core_Resolution.py @@ -13,35 +13,40 @@ 5. for more details, see https://docs.pytest.org/en/stable/usage.html ''' +import pytest import pyleoclim as pyleo class TestUIResolutionDescribe: """Tests for Resolution.describe()""" - - def test_describe_t0(self,unevenly_spaced_series): - resolution = unevenly_spaced_series.resolution() + @pytest.mark.parametrize('series', ['unevenly_spaced_series','unevenly_spaced_series_nans']) + def test_describe_t0(self,series,request): + series = request.getfixturevalue(series) + resolution = series.resolution() resolution.describe() class TestUIResolutionPlot: """Tests for Resolution.plot()""" - - def test_plot_t0(self,unevenly_spaced_series): - resolution = unevenly_spaced_series.resolution() + @pytest.mark.parametrize('series', ['unevenly_spaced_series','unevenly_spaced_series_nans']) + def test_plot_t0(self,series,request): + series = request.getfixturevalue(series) + resolution = series.resolution() fig, ax = resolution.plot() pyleo.closefig(fig) class TestUIHistPlot: """Tests for Resolution.plot()""" - - def test_histplot_t0(self,unevenly_spaced_series): - resolution = unevenly_spaced_series.resolution() + @pytest.mark.parametrize('series', ['unevenly_spaced_series','unevenly_spaced_series_nans']) + def test_histplot_t0(self,series,request): + series = request.getfixturevalue(series) + resolution = series.resolution() fig, ax = resolution.histplot() pyleo.closefig(fig) class TestUIDashboard: """Tests for Resolution.dashboard()""" - - def test_dashboard_t0(self,unevenly_spaced_series): - resolution = unevenly_spaced_series.resolution() + @pytest.mark.parametrize('series', ['unevenly_spaced_series','unevenly_spaced_series_nans']) + def test_dashboard_t0(self,series,request): + series = request.getfixturevalue(series) + resolution = series.resolution() fig, ax = resolution.dashboard() pyleo.closefig(fig) \ No newline at end of file From e75dab0ce312c37311afffbd41bf8c87d0551887 Mon Sep 17 00:00:00 2001 From: Alexander James Date: Thu, 15 Jun 2023 16:20:29 -0700 Subject: [PATCH 5/5] make series.resolution manage nans --- pyleoclim/core/series.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pyleoclim/core/series.py b/pyleoclim/core/series.py index 553d273c..eb6d01f4 100644 --- a/pyleoclim/core/series.py +++ b/pyleoclim/core/series.py @@ -4017,16 +4017,22 @@ def resolution(self): resolution.dashboard() """ - x = self.time - if any(np.isnan(x)): #Drop nans from x if they're present - x = x[~np.isnan(x)] + copy = self.copy() + + x = copy.time + v = copy.value + + if any(np.isnan(v)): + v,x = tsbase.dropna(ts=x,ys=v) + copy.time = x + copy.value = v res,_,_ = tsbase.resolution(x=x) resolution = Resolution( resolution = res, - timeseries = self + timeseries = copy ) return resolution