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

Template for unit tests #187

Merged
merged 26 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e2a30df
start unit tests
RondeauG Apr 13, 2023
08614f0
Merge branch 'main' into unittests
RondeauG May 9, 2023
8fc3ca5
use test_timeseries
RondeauG May 9, 2023
795aaf5
cleanup and reqs
RondeauG May 9, 2023
5b1bf90
Merge branch 'main' into unittests
RondeauG May 10, 2023
2b58541
proper climatological_mean tests and small fixes
RondeauG May 10, 2023
8710457
remove outdated comments
RondeauG May 10, 2023
df6e569
manage deltas with no time
RondeauG May 11, 2023
159880f
convert_calendar
RondeauG May 11, 2023
dac02be
test Datetime360Day
RondeauG May 11, 2023
163ad8a
test more cftime calendars
RondeauG May 11, 2023
2be785d
github is eating my changes :(
RondeauG May 11, 2023
61c3b11
Use parametrize - assert for scalars
aulemahal May 26, 2023
7ebe2b0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 26, 2023
7614ce1
changes from code review, fixed QS-DEC test series
RondeauG May 31, 2023
0593e29
Merge branch 'main' into unittests
RondeauG May 31, 2023
bb201b7
Merge branch 'main' into unittests
Zeitsperre Jun 1, 2023
e0de794
adjust environment config and test logic
Zeitsperre Jun 1, 2023
b2262b5
update HISTORY.rst
Zeitsperre Jun 1, 2023
9c9dcb9
revert bad change
Zeitsperre Jun 1, 2023
f457e8a
add coveralls actions to workflows, update deprecated provision action
Zeitsperre Jun 1, 2023
5468e83
typo fix
Zeitsperre Jun 1, 2023
1581b1b
more interesting debug information
Zeitsperre Jun 1, 2023
9b070c7
update history and add coveralls badge
Zeitsperre Jun 1, 2023
95fbd29
reverse change to processing_level
RondeauG Jun 5, 2023
02ee10a
Merge remote-tracking branch 'origin/unittests' into unittests
RondeauG Jun 5, 2023
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
28 changes: 28 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import shutil
from pathlib import Path

import pandas as pd
import pytest
import xarray as xr

notebooks = Path().cwd().parent / "docs" / "notebooks"

Expand All @@ -20,3 +22,29 @@ def remove_data_folder():
shutil.rmtree(data)

request.addfinalizer(remove_data_folder)


@pytest.fixture
def tas_series_1d():
"""Create a temperature time series."""

def _tas_series(values, start="7/1/2000", units="K", freq="D", as_dataset=True):
coords = pd.date_range(start, periods=len(values), freq=freq)
da = xr.DataArray(
values,
coords=[coords],
dims="time",
name="tas",
attrs={
"standard_name": "air_temperature",
"cell_methods": "time: mean within days",
"units": units,
},
)
da.name = "tas"
if as_dataset:
return da.to_dataset()
else:
return da

return _tas_series
13 changes: 13 additions & 0 deletions tests/test_aggregate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import numpy as np

from xscen import aggregate


class TestClimatologicalMean:
def test_monthly_all_default(self, tas_series_1d):
ds = tas_series_1d(
np.tile(np.arange(1, 13), 3), start="2001-01-01", freq="MS", as_dataset=True
)
out = aggregate.climatological_mean(ds)
assert out.attrs["cat:processing_level"] == "climatology"
np.testing.assert_array_equal(out.tas, np.arange(1, 13))
5 changes: 5 additions & 0 deletions xscen/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def climatological_mean(
Returns a Dataset of the climatological mean

"""
if xr.infer_freq(ds.time) == "D":
raise NotImplementedError(
"xs.climatological_mean does not currently support daily data."
)

# there is one less occurrence when a period crosses years
freq_across_year = [
f"{f}-{mon}"
Expand Down