(dask)
| 966 | @requires_cftime |
| 967 | @pytest.mark.parametrize("dask", [True, False]) |
| 968 | def test_datetime_to_numeric_cftime(dask): |
| 969 | if dask and not has_dask: |
| 970 | pytest.skip("requires dask") |
| 971 | |
| 972 | times = date_range( |
| 973 | "2000", periods=5, freq="7D", calendar="standard", use_cftime=True |
| 974 | ).values |
| 975 | if dask: |
| 976 | import dask.array |
| 977 | |
| 978 | times = dask.array.from_array(times, chunks=-1) |
| 979 | with raise_if_dask_computes(): |
| 980 | result = duck_array_ops.datetime_to_numeric(times, datetime_unit="h", dtype=int) |
| 981 | expected = 24 * np.arange(0, 35, 7) |
| 982 | np.testing.assert_array_equal(result, expected) |
| 983 | |
| 984 | offset = times[1] |
| 985 | with raise_if_dask_computes(): |
| 986 | result = duck_array_ops.datetime_to_numeric( |
| 987 | times, offset=offset, datetime_unit="h", dtype=int |
| 988 | ) |
| 989 | expected = 24 * np.arange(-7, 28, 7) |
| 990 | np.testing.assert_array_equal(result, expected) |
| 991 | |
| 992 | dtype = np.float32 |
| 993 | with raise_if_dask_computes(): |
| 994 | result = duck_array_ops.datetime_to_numeric( |
| 995 | times, datetime_unit="h", dtype=dtype |
| 996 | ) |
| 997 | expected2: Any = 24 * np.arange(0, 35, 7).astype(dtype) |
| 998 | np.testing.assert_array_equal(result, expected2) |
| 999 | |
| 1000 | with raise_if_dask_computes(): |
| 1001 | if dask: |
| 1002 | time = dask.array.asarray(times[1]) |
| 1003 | else: |
| 1004 | time = np.asarray(times[1]) |
| 1005 | result = duck_array_ops.datetime_to_numeric( |
| 1006 | time, offset=times[0], datetime_unit="h", dtype=int |
| 1007 | ) |
| 1008 | expected3 = np.array(24 * 7).astype(int) |
| 1009 | np.testing.assert_array_equal(result, expected3) |
| 1010 | |
| 1011 | |
| 1012 | @requires_cftime |
nothing calls this directly
no test coverage detected
searching dependent graphs…