Skip to content

Commit 49dfd6a

Browse files
rcaneilldcherian
andauthored
fix test for datetime (#301)
Co-authored-by: dcherian <[email protected]>
1 parent 81d3841 commit 49dfd6a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

cf_xarray/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ def LooseVersion(vstring):
6565

6666
has_pint, requires_pint = _importorskip("pint")
6767
has_shapely, requires_shapely = _importorskip("shapely")
68+
has_cftime, requires_cftime = _importorskip("cftime")

cf_xarray/tests/test_accessor.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
romsds,
2828
vert,
2929
)
30-
from . import raise_if_dask_computes, requires_pint
30+
from . import raise_if_dask_computes, requires_cftime, requires_pint
3131

3232
mpl.use("Agg")
3333

@@ -1424,10 +1424,17 @@ def test_add_canonical_attributes_0_dim():
14241424
).cf.add_canonical_attributes()
14251425

14261426

1427-
def test_datetime_like():
1427+
@requires_cftime
1428+
@pytest.mark.parametrize("reshape", [False, True])
1429+
def test_datetime_like(reshape):
14281430
"""test for 0 or >= 2 time dimensions"""
1431+
import cftime
1432+
1433+
data = cftime.datetime(2022, 1, 12)
1434+
if reshape:
1435+
data = [[data]]
14291436
da = xr.DataArray(
1430-
np.timedelta64(1, "D"),
1437+
data,
14311438
attrs={"standard_name": "sea_water_age_since_surface_contact"},
14321439
)
14331440
new_attrs = da.cf.add_canonical_attributes().attrs

0 commit comments

Comments
 (0)