(
cftime_rounding_dataarray, cftime_date_type, use_dask
)
| 678 | @requires_dask |
| 679 | @pytest.mark.parametrize("use_dask", [False, True]) |
| 680 | def test_cftime_round_accessor( |
| 681 | cftime_rounding_dataarray, cftime_date_type, use_dask |
| 682 | ) -> None: |
| 683 | import dask.array as da |
| 684 | |
| 685 | freq = "D" |
| 686 | expected = xr.DataArray( |
| 687 | [ |
| 688 | [cftime_date_type(1, 1, 1, 0), cftime_date_type(1, 1, 2, 0)], |
| 689 | [cftime_date_type(1, 1, 2, 0), cftime_date_type(1, 1, 2, 0)], |
| 690 | ], |
| 691 | name="round", |
| 692 | ) |
| 693 | |
| 694 | if use_dask: |
| 695 | chunks = {"dim_0": 1} |
| 696 | # Currently a compute is done to inspect a single value of the array |
| 697 | # if it is of object dtype to check if it is a cftime.datetime (if not |
| 698 | # we raise an error when using the dt accessor). |
| 699 | with raise_if_dask_computes(max_computes=1): |
| 700 | result = cftime_rounding_dataarray.chunk(chunks).dt.round(freq) |
| 701 | expected = expected.chunk(chunks) |
| 702 | assert isinstance(result.data, da.Array) |
| 703 | assert result.chunks == expected.chunks |
| 704 | else: |
| 705 | result = cftime_rounding_dataarray.dt.round(freq) |
| 706 | |
| 707 | assert_identical(result, expected) |
| 708 | |
| 709 | |
| 710 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected
searching dependent graphs…