Skip to content

Commit eb0fbd7

Browse files
authored
Use duckarray assertions in test_coding_times (#9226)
1 parent 7ff5d8d commit eb0fbd7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

xarray/tests/test_coding_times.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
FirstElementAccessibleArray,
4545
arm_xfail,
4646
assert_array_equal,
47+
assert_duckarray_allclose,
48+
assert_duckarray_equal,
4749
assert_no_warnings,
4850
has_cftime,
4951
requires_cftime,
@@ -144,13 +146,13 @@ def test_cf_datetime(num_dates, units, calendar) -> None:
144146
assert (abs_diff <= np.timedelta64(1, "s")).all()
145147
encoded, _, _ = encode_cf_datetime(actual, units, calendar)
146148

147-
assert_array_equal(num_dates, np.round(encoded, 1))
149+
assert_duckarray_allclose(num_dates, encoded)
148150
if hasattr(num_dates, "ndim") and num_dates.ndim == 1 and "1000" not in units:
149151
# verify that wrapping with a pandas.Index works
150152
# note that it *does not* currently work to put
151153
# non-datetime64 compatible dates into a pandas.Index
152154
encoded, _, _ = encode_cf_datetime(pd.Index(actual), units, calendar)
153-
assert_array_equal(num_dates, np.round(encoded, 1))
155+
assert_duckarray_allclose(num_dates, encoded)
154156

155157

156158
@requires_cftime
@@ -893,10 +895,10 @@ def test_time_units_with_timezone_roundtrip(calendar) -> None:
893895
)
894896

895897
if calendar in _STANDARD_CALENDARS:
896-
np.testing.assert_array_equal(result_num_dates, expected_num_dates)
898+
assert_duckarray_equal(result_num_dates, expected_num_dates)
897899
else:
898900
# cftime datetime arithmetic is not quite exact.
899-
np.testing.assert_allclose(result_num_dates, expected_num_dates)
901+
assert_duckarray_allclose(result_num_dates, expected_num_dates)
900902

901903
assert result_units == expected_units
902904
assert result_calendar == calendar

0 commit comments

Comments
 (0)