Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

294 utils bugfix 2 #314

Merged
merged 3 commits into from
Feb 2, 2023
Merged
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
12 changes: 11 additions & 1 deletion pyleoclim/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pandas as pd
import numpy as np
import pyleoclim as pyleo
import pytest


Expand All @@ -16,4 +17,13 @@ def dataframe():
"""Pandas dataframe with a non-datetime index and random values"""
length = 5
df = pd.DataFrame(np.ones(length))
return df
return df

@pytest.fixture
def unevenly_spaced_series():
"""Pyleoclim series with unevenly spaced time axis"""
length = 10
t = np.linspace(1,length,length) ** 2
v = np.ones(length)
series = pyleo.Series(t,v)
return series
16 changes: 14 additions & 2 deletions pyleoclim/tests/test_utils_tsutils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import pytest
from pyleoclim.utils import tsutils
from pyleoclim.utils import tsutils, tsbase
import numpy as np


Expand Down Expand Up @@ -142,4 +142,16 @@ def test_convert_datetime_index_nondt_index(dataframe):
dataframe.index,
time_unit,
time_name=time_name,
)
)

def test_bin_t0(unevenly_spaced_series):
res_dict = tsutils.bin(unevenly_spaced_series.time,unevenly_spaced_series.value)
t = res_dict['bins']
v = res_dict['binned_values']
assert isinstance(t,np.ndarray)
assert isinstance(v,np.ndarray)

def test_bin_t1(unevenly_spaced_series):
res_dict = tsutils.bin(unevenly_spaced_series.time,unevenly_spaced_series.value,evenly_spaced=True)
t = res_dict['bins']
assert tsbase.is_evenly_spaced(t)
4 changes: 2 additions & 2 deletions pyleoclim/utils/tsutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ def bin(x, y, bin_size=None, start=None, stop=None, evenly_spaced = True):
error.append(np.nanstd(y[idx]))

res_dict = {
'bins': bins,
'binned_values': binned_values,
'bins': np.array(bins),
'binned_values': np.array(binned_values),
'n': n,
'error': error,
}
Expand Down