MCPcopy Index your code
hub / github.com/pydata/xarray / test_datetime_to_numeric_datetime64

Function test_datetime_to_numeric_datetime64

xarray/tests/test_duck_array_ops.py:934–963  ·  view source on GitHub ↗
(dask, time_unit: PDDatetimeUnitOptions)

Source from the content-addressed store, hash-verified

932
933@pytest.mark.parametrize("dask", [True, False])
934def 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

Callers

nothing calls this directly

Calls 4

raise_if_dask_computesFunction · 0.90
arangeMethod · 0.80
from_arrayMethod · 0.45
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…