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 diff --git a/pyleoclim/core/series.py b/pyleoclim/core/series.py index 43f97883..eb6d01f4 100644 --- a/pyleoclim/core/series.py +++ b/pyleoclim/core/series.py @@ -4017,12 +4017,22 @@ def resolution(self): resolution.dashboard() """ - - res,_,_ = tsbase.resolution(self.time) + + 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 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""" 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