(self, from_Dt)
| 352 | |
| 353 | @pytest.mark.parametrize("from_Dt", simple_dtypes) |
| 354 | def test_numeric_to_times(self, from_Dt): |
| 355 | # We currently only implement contiguous loops, so only need to |
| 356 | # test those. |
| 357 | from_dt = from_Dt() |
| 358 | |
| 359 | time_dtypes = [np.dtype("M8"), np.dtype("M8[ms]"), np.dtype("M8[4D]"), |
| 360 | np.dtype("m8"), np.dtype("m8[ms]"), np.dtype("m8[4D]")] |
| 361 | for time_dt in time_dtypes: |
| 362 | cast = get_castingimpl(type(from_dt), type(time_dt)) |
| 363 | |
| 364 | casting, (from_res, to_res), view_off = cast._resolve_descriptors( |
| 365 | (from_dt, time_dt)) |
| 366 | |
| 367 | assert from_res is from_dt |
| 368 | assert to_res is time_dt |
| 369 | del from_res, to_res |
| 370 | |
| 371 | assert casting & CAST_TABLE[from_Dt][type(time_dt)] |
| 372 | assert view_off is None |
| 373 | |
| 374 | int64_dt = np.dtype(np.int64) |
| 375 | arr1, arr2, values = self.get_data(from_dt, int64_dt) |
| 376 | arr2 = arr2.view(time_dt) |
| 377 | arr2[...] = np.datetime64("NaT") |
| 378 | |
| 379 | if time_dt == np.dtype("M8"): |
| 380 | # This is a bit of a strange path, and could probably be removed |
| 381 | arr1[-1] = 0 # ensure at least one value is not NaT |
| 382 | |
| 383 | # The cast currently succeeds, but the values are invalid: |
| 384 | cast._simple_strided_call((arr1, arr2)) |
| 385 | with pytest.raises(ValueError): |
| 386 | str(arr2[-1]) # e.g. conversion to string fails |
| 387 | return |
| 388 | |
| 389 | cast._simple_strided_call((arr1, arr2)) |
| 390 | |
| 391 | assert [int(v) for v in arr2.tolist()] == values |
| 392 | |
| 393 | # Check that the same results are achieved for strided loops |
| 394 | arr1_o, arr2_o = self.get_data_variation(arr1, arr2, True, False) |
| 395 | cast._simple_strided_call((arr1_o, arr2_o)) |
| 396 | |
| 397 | assert_array_equal(arr2_o, arr2) |
| 398 | assert arr2_o.tobytes() == arr2.tobytes() |
| 399 | |
| 400 | @pytest.mark.parametrize( |
| 401 | ["from_dt", "to_dt", "expected_casting", "expected_view_off", |
nothing calls this directly
no test coverage detected