Skip to content
forked from pydata/xarray

Commit

Permalink
start adding tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Nov 13, 2019
1 parent a8b261a commit 809aa73
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
except ImportError:
pass

try:
import cftime
except ImportError:
pass


@pytest.mark.flaky
@pytest.mark.skip(reason="maybe flaky")
Expand Down Expand Up @@ -2149,3 +2154,52 @@ def test_yticks_kwarg(self, da):
da.plot(yticks=np.arange(5))
expected = np.arange(5)
assert np.all(plt.gca().get_yticks() == expected)


@requires_matplotlib
class TestDataArrayGroupByPlot:
@requires_cftime
@requires_nc_time_axis
@pytest.mark.parametrize(
"time",
[
cftime.num2date(
np.arange(0, 730), "days since 0001-01-01 00:00:00", calendar="noleap"
),
pd.date_range("2001-01-01", freq="12H", periods=730),
],
)
def test_time_grouping(self, time):
# create spatial coordinate
lev = np.arange(100)

# Create sample Dataset
ds = Dataset(
{
"sample_data": (["time", "lev"], np.random.rand(time.size, lev.size)),
"independent_data": (["lev"], np.random.rand(lev.size)),
},
coords={"time": (["time"], time), "lev": (["lev"], lev)},
)

ds.sample_data.groupby("time.month").plot(
col="month", col_wrap=4, x="time", sharey=True
)

def test_stacked_groupby(self):
ds = Dataset(
{
"variable": (
("lat", "lon", "time"),
np.arange(60.0).reshape((4, 3, 5)),
),
"id": (("lat", "lon"), np.arange(12.0).reshape((4, 3))),
},
coords={
"lat": np.arange(4),
"lon": np.arange(3),
"time": pd.date_range(start="2001-01-01", freq="D", periods=5),
},
)

ds.variable.groupby(ds.id).plot.line(col="id", col_wrap=2)

0 comments on commit 809aa73

Please sign in to comment.