Skip to content

Commit

Permalink
Update test_coding_times.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Illviljan committed Jul 10, 2024
1 parent cedff32 commit d43c0c1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions xarray/tests/test_coding_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
FirstElementAccessibleArray,
arm_xfail,
assert_array_equal,
assert_duckarray_allclose,
assert_duckarray_equal,
assert_no_warnings,
has_cftime,
requires_cftime,
Expand Down Expand Up @@ -144,13 +146,13 @@ def test_cf_datetime(num_dates, units, calendar) -> None:
assert (abs_diff <= np.timedelta64(1, "s")).all()
encoded, _, _ = encode_cf_datetime(actual, units, calendar)

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


@requires_cftime
Expand Down Expand Up @@ -893,10 +895,10 @@ def test_time_units_with_timezone_roundtrip(calendar) -> None:
)

if calendar in _STANDARD_CALENDARS:
np.testing.assert_array_equal(result_num_dates, expected_num_dates)
assert_duckarray_equal(result_num_dates, expected_num_dates)
else:
# cftime datetime arithmetic is not quite exact.
np.testing.assert_allclose(result_num_dates, expected_num_dates)
assert_duckarray_allclose(result_num_dates, expected_num_dates)

assert result_units == expected_units
assert result_calendar == calendar
Expand Down

0 comments on commit d43c0c1

Please sign in to comment.