|
20 | 20 | import bz2
|
21 | 21 | import threading
|
22 | 22 | import time
|
| 23 | +from packaging.version import Version |
23 | 24 |
|
24 | 25 | import numpy as np
|
25 | 26 |
|
|
68 | 69 | IUINT_TYPES = INT_TYPES + np.sctypes['uint']
|
69 | 70 | NUMERIC_TYPES = CFLOAT_TYPES + IUINT_TYPES
|
70 | 71 |
|
| 72 | +FP_RUNTIME_WARN = Version(np.__version__) >= Version('1.24.0.dev0+239') |
| 73 | + |
71 | 74 |
|
72 | 75 | def test__is_compressed_fobj():
|
73 | 76 | # _is_compressed helper function
|
@@ -413,7 +416,7 @@ def test_a2f_nan2zero():
|
413 | 416 | # How weird? Look at arr.astype(np.int64)
|
414 | 417 | with np.errstate(invalid='ignore'):
|
415 | 418 | data_back = write_return(arr, str_io, np.int64, nan2zero=False)
|
416 |
| - assert_array_equal(data_back, arr.astype(np.int64)) |
| 419 | + assert_array_equal(data_back, arr.astype(np.int64)) |
417 | 420 |
|
418 | 421 |
|
419 | 422 | def test_a2f_nan2zero_scaling():
|
@@ -672,40 +675,43 @@ def test_a2f_nan2zero_range():
|
672 | 675 | arr = np.array([-1, 0, 1, np.nan], dtype=dt)
|
673 | 676 | # Error occurs for arrays without nans too
|
674 | 677 | arr_no_nan = np.array([-1, 0, 1, 2], dtype=dt)
|
675 |
| - warn_type = np.ComplexWarning if np.issubdtype(dt, np.complexfloating) else None |
| 678 | + complex_warn = (np.ComplexWarning,) if np.issubdtype(dt, np.complexfloating) else () |
| 679 | + # Casting nan to int will produce a RuntimeWarning in numpy 1.24 |
| 680 | + nan_warn = (RuntimeWarning,) if FP_RUNTIME_WARN else () |
| 681 | + c_and_n_warn = complex_warn + nan_warn |
676 | 682 | # No errors from explicit thresholding
|
677 | 683 | # mn thresholding excluding zero
|
678 |
| - with pytest.warns(warn_type) if warn_type else error_warnings(): |
| 684 | + with pytest.warns(complex_warn) if complex_warn else error_warnings(): |
679 | 685 | assert_array_equal([1, 1, 1, 0],
|
680 | 686 | write_return(arr, fobj, np.int8, mn=1))
|
681 | 687 | # mx thresholding excluding zero
|
682 |
| - with pytest.warns(warn_type) if warn_type else error_warnings(): |
| 688 | + with pytest.warns(complex_warn) if complex_warn else error_warnings(): |
683 | 689 | assert_array_equal([-1, -1, -1, 0],
|
684 | 690 | write_return(arr, fobj, np.int8, mx=-1))
|
685 | 691 | # Errors from datatype threshold after scaling
|
686 |
| - with pytest.warns(warn_type) if warn_type else error_warnings(): |
| 692 | + with pytest.warns(complex_warn) if complex_warn else error_warnings(): |
687 | 693 | back_arr = write_return(arr, fobj, np.int8, intercept=128)
|
688 | 694 | assert_array_equal([-128, -128, -127, -128], back_arr)
|
689 | 695 | with pytest.raises(ValueError):
|
690 | 696 | write_return(arr, fobj, np.int8, intercept=129)
|
691 | 697 | with pytest.raises(ValueError):
|
692 | 698 | write_return(arr_no_nan, fobj, np.int8, intercept=129)
|
693 | 699 | # OK with nan2zero false, but we get whatever nan casts to
|
694 |
| - with pytest.warns(warn_type) if warn_type else error_warnings(): |
| 700 | + with pytest.warns(c_and_n_warn) if c_and_n_warn else error_warnings(): |
695 | 701 | nan_cast = np.array(np.nan, dtype=dt).astype(np.int8)
|
696 |
| - with pytest.warns(warn_type) if warn_type else error_warnings(): |
| 702 | + with pytest.warns(c_and_n_warn) if c_and_n_warn else error_warnings(): |
697 | 703 | back_arr = write_return(arr, fobj, np.int8, intercept=129, nan2zero=False)
|
698 | 704 | assert_array_equal([-128, -128, -128, nan_cast], back_arr)
|
699 | 705 | # divslope
|
700 |
| - with pytest.warns(warn_type) if warn_type else error_warnings(): |
| 706 | + with pytest.warns(complex_warn) if complex_warn else error_warnings(): |
701 | 707 | back_arr = write_return(arr, fobj, np.int8, intercept=256, divslope=2)
|
702 | 708 | assert_array_equal([-128, -128, -128, -128], back_arr)
|
703 | 709 | with pytest.raises(ValueError):
|
704 | 710 | write_return(arr, fobj, np.int8, intercept=257.1, divslope=2)
|
705 | 711 | with pytest.raises(ValueError):
|
706 | 712 | write_return(arr_no_nan, fobj, np.int8, intercept=257.1, divslope=2)
|
707 | 713 | # OK with nan2zero false
|
708 |
| - with pytest.warns(warn_type) if warn_type else error_warnings(): |
| 714 | + with pytest.warns(c_and_n_warn) if c_and_n_warn else error_warnings(): |
709 | 715 | back_arr = write_return(arr, fobj, np.int8,
|
710 | 716 | intercept=257.1, divslope=2, nan2zero=False)
|
711 | 717 | assert_array_equal([-128, -128, -128, nan_cast], back_arr)
|
|
0 commit comments