-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
enable internal plotting with cftime datetime #2665
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
Changes from all commits
7b216b3
879cdc5
b67f532
0479829
970a6a5
849512f
afe365c
69fe822
52867d7
4bb3446
3c98d27
15a6c86
6668f8e
daa5508
9d19946
985d367
325b00a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ channels: | |
dependencies: | ||
- python=3.7 | ||
- cftime | ||
- nc-time-axis | ||
- dask | ||
- distributed | ||
- h5py | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ channels: | |
dependencies: | ||
- python=3.7 | ||
- cftime | ||
- nc-time-axis | ||
- dask | ||
- distributed | ||
- h5py | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -17,7 +17,9 @@ | |||
|
||||
from . import ( | ||||
assert_array_equal, assert_equal, raises_regex, requires_cftime, | ||||
requires_matplotlib, requires_matplotlib2, requires_seaborn) | ||||
requires_matplotlib, requires_matplotlib2, requires_seaborn, | ||||
requires_nc_time_axis) | ||||
from . import has_nc_time_axis | ||||
|
||||
# import mpl and change the backend before other mpl imports | ||||
try: | ||||
|
@@ -1828,6 +1830,61 @@ def test_datetime_line_plot(self): | |||
self.darray.plot.line() | ||||
|
||||
|
||||
@requires_nc_time_axis | ||||
@requires_cftime | ||||
class TestCFDatetimePlot(PlotTestCase): | ||||
@pytest.fixture(autouse=True) | ||||
def setUp(self): | ||||
''' | ||||
Create a DataArray with a time-axis that contains cftime.datetime | ||||
objects. | ||||
''' | ||||
# case for 1d array | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
data = np.random.rand(4, 12) | ||||
time = xr.cftime_range(start='2017', | ||||
periods=12, | ||||
freq='1M', | ||||
calendar='noleap') | ||||
darray = DataArray(data, dims=['x', 'time']) | ||||
darray.coords['time'] = time | ||||
|
||||
self.darray = darray | ||||
|
||||
def test_cfdatetime_line_plot(self): | ||||
jbusecke marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
self.darray.isel(x=0).plot.line() | ||||
|
||||
def test_cfdatetime_pcolormesh_plot(self): | ||||
self.darray.plot.pcolormesh() | ||||
|
||||
def test_cfdatetime_contour_plot(self): | ||||
self.darray.plot.contour() | ||||
|
||||
|
||||
@requires_cftime | ||||
@pytest.mark.skipif(has_nc_time_axis, reason='nc_time_axis is installed') | ||||
class TestNcAxisNotInstalled(PlotTestCase): | ||||
@pytest.fixture(autouse=True) | ||||
def setUp(self): | ||||
''' | ||||
Create a DataArray with a time-axis that contains cftime.datetime | ||||
objects. | ||||
''' | ||||
month = np.arange(1, 13, 1) | ||||
data = np.sin(2 * np.pi * month / 12.0) | ||||
darray = DataArray(data, dims=['time']) | ||||
darray.coords['time'] = xr.cftime_range(start='2017', | ||||
periods=12, | ||||
freq='1M', | ||||
calendar='noleap') | ||||
|
||||
self.darray = darray | ||||
|
||||
def test_ncaxis_notinstalled_line_plot(self): | ||||
with raises_regex(ImportError, | ||||
'optional `nc-time-axis`'): | ||||
self.darray.plot.line() | ||||
|
||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think the ones I added look ok?
spencerkclark marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
@requires_seaborn | ||||
def test_import_seaborn_no_warning(): | ||||
# GH1633 | ||||
|
@@ -1844,27 +1901,6 @@ def test_plot_seaborn_no_import_warning(): | |||
assert len(record) == 0 | ||||
|
||||
|
||||
@requires_cftime | ||||
def test_plot_cftime_coordinate_error(): | ||||
cftime = _import_cftime() | ||||
time = cftime.num2date(np.arange(5), units='days since 0001-01-01', | ||||
calendar='noleap') | ||||
data = DataArray(np.arange(5), coords=[time], dims=['time']) | ||||
with raises_regex(TypeError, | ||||
'requires coordinates to be numeric or dates'): | ||||
data.plot() | ||||
|
||||
|
||||
@requires_cftime | ||||
def test_plot_cftime_data_error(): | ||||
cftime = _import_cftime() | ||||
data = cftime.num2date(np.arange(5), units='days since 0001-01-01', | ||||
calendar='noleap') | ||||
data = DataArray(data, coords=[np.arange(5)], dims=['x']) | ||||
with raises_regex(NotImplementedError, 'cftime.datetime'): | ||||
data.plot() | ||||
|
||||
|
||||
test_da_list = [DataArray(easy_array((10, ))), | ||||
DataArray(easy_array((10, 3))), | ||||
DataArray(easy_array((10, 3, 2)))] | ||||
|
Uh oh!
There was an error while loading. Please reload this page.