(dask, time_unit: PDDatetimeUnitOptions)
| 932 | |
| 933 | @pytest.mark.parametrize("dask", [True, False]) |
| 934 | def test_datetime_to_numeric_datetime64(dask, time_unit: PDDatetimeUnitOptions): |
| 935 | if dask and not has_dask: |
| 936 | pytest.skip("requires dask") |
| 937 | |
| 938 | times = pd.date_range("2000", periods=5, freq="7D").as_unit(time_unit).values |
| 939 | if dask: |
| 940 | import dask.array |
| 941 | |
| 942 | times = dask.array.from_array(times, chunks=-1) |
| 943 | |
| 944 | with raise_if_dask_computes(): |
| 945 | result = duck_array_ops.datetime_to_numeric(times, datetime_unit="h") |
| 946 | expected = 24 * np.arange(0, 35, 7) |
| 947 | np.testing.assert_array_equal(result, expected) |
| 948 | |
| 949 | offset = times[1] |
| 950 | with raise_if_dask_computes(): |
| 951 | result = duck_array_ops.datetime_to_numeric( |
| 952 | times, offset=offset, datetime_unit="h" |
| 953 | ) |
| 954 | expected = 24 * np.arange(-7, 28, 7) |
| 955 | np.testing.assert_array_equal(result, expected) |
| 956 | |
| 957 | dtype = np.float32 |
| 958 | with raise_if_dask_computes(): |
| 959 | result = duck_array_ops.datetime_to_numeric( |
| 960 | times, datetime_unit="h", dtype=dtype |
| 961 | ) |
| 962 | expected2 = 24 * np.arange(0, 35, 7).astype(dtype) |
| 963 | np.testing.assert_array_equal(result, expected2) |
| 964 | |
| 965 | |
| 966 | @requires_cftime |
nothing calls this directly
no test coverage detected
searching dependent graphs…