(dtype, loop_dtype)
| 1534 | "ignore::DeprecationWarning", |
| 1535 | ) |
| 1536 | def test_iter_copy_casts(dtype, loop_dtype): |
| 1537 | # Ensure the dtype is never flexible: |
| 1538 | if loop_dtype.lower() == "m": |
| 1539 | loop_dtype = loop_dtype + "[ms]" |
| 1540 | elif np.dtype(loop_dtype).itemsize == 0: |
| 1541 | loop_dtype = loop_dtype + "50" |
| 1542 | |
| 1543 | # Make things a bit more interesting by requiring a byte-swap as well: |
| 1544 | arr = np.ones(1000, dtype=np.dtype(dtype).newbyteorder()) |
| 1545 | try: |
| 1546 | expected = arr.astype(loop_dtype) |
| 1547 | except Exception: |
| 1548 | # Some casts are not possible, do not worry about them |
| 1549 | return |
| 1550 | |
| 1551 | it = np.nditer((arr,), ["buffered", "external_loop", "refs_ok"], |
| 1552 | op_dtypes=[loop_dtype], casting="unsafe") |
| 1553 | |
| 1554 | if np.issubdtype(np.dtype(loop_dtype), np.number): |
| 1555 | # Casting to strings may be strange, but for simple dtypes do not rely |
| 1556 | # on the cast being correct: |
| 1557 | assert_array_equal(expected, np.ones(1000, dtype=loop_dtype)) |
| 1558 | |
| 1559 | it_copy = it.copy() |
| 1560 | res = next(it) |
| 1561 | del it |
| 1562 | res_copy = next(it_copy) |
| 1563 | del it_copy |
| 1564 | |
| 1565 | assert_array_equal(res, expected) |
| 1566 | assert_array_equal(res_copy, expected) |
| 1567 | |
| 1568 | |
| 1569 | def test_iter_copy_casts_structured(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…