|
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
|
@@ -672,50 +675,45 @@ 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(): |
695 |
| - # XXX NP1.24 |
696 |
| - # Casting nan to int will produce a RuntimeWarning in numpy 1.24 |
697 |
| - # Change to expecting this warning when this becomes our minimum |
698 |
| - with np.errstate(invalid='ignore'): |
699 |
| - nan_cast = np.array(np.nan, dtype=dt).astype(np.int8) |
700 |
| - with pytest.warns(warn_type) if warn_type else error_warnings(): |
701 |
| - # XXX NP1.24 - expect RuntimeWarning |
702 |
| - with np.errstate(invalid='ignore'): |
703 |
| - back_arr = write_return(arr, fobj, np.int8, intercept=129, nan2zero=False) |
| 700 | + with pytest.warns(c_and_n_warn) if c_and_n_warn else error_warnings(): |
| 701 | + nan_cast = np.array(np.nan, dtype=dt).astype(np.int8) |
| 702 | + with pytest.warns(c_and_n_warn) if c_and_n_warn else error_warnings(): |
| 703 | + back_arr = write_return(arr, fobj, np.int8, intercept=129, nan2zero=False) |
704 | 704 | assert_array_equal([-128, -128, -128, nan_cast], back_arr)
|
705 | 705 | # divslope
|
706 |
| - with pytest.warns(warn_type) if warn_type else error_warnings(): |
| 706 | + with pytest.warns(complex_warn) if complex_warn else error_warnings(): |
707 | 707 | back_arr = write_return(arr, fobj, np.int8, intercept=256, divslope=2)
|
708 | 708 | assert_array_equal([-128, -128, -128, -128], back_arr)
|
709 | 709 | with pytest.raises(ValueError):
|
710 | 710 | write_return(arr, fobj, np.int8, intercept=257.1, divslope=2)
|
711 | 711 | with pytest.raises(ValueError):
|
712 | 712 | write_return(arr_no_nan, fobj, np.int8, intercept=257.1, divslope=2)
|
713 | 713 | # OK with nan2zero false
|
714 |
| - with pytest.warns(warn_type) if warn_type else error_warnings(): |
715 |
| - # XXX NP1.24 - expect RuntimeWarning |
716 |
| - with np.errstate(invalid='ignore'): |
717 |
| - back_arr = write_return(arr, fobj, np.int8, |
718 |
| - intercept=257.1, divslope=2, nan2zero=False) |
| 714 | + with pytest.warns(c_and_n_warn) if c_and_n_warn else error_warnings(): |
| 715 | + back_arr = write_return(arr, fobj, np.int8, |
| 716 | + intercept=257.1, divslope=2, nan2zero=False) |
719 | 717 | assert_array_equal([-128, -128, -128, nan_cast], back_arr)
|
720 | 718 |
|
721 | 719 |
|
|
0 commit comments