|
8 | 8 |
|
9 | 9 | import bottleneck as bn |
10 | 10 |
|
11 | | -from .util import DTYPES, INT_DTYPES, array_order, arrays |
| 11 | +from .util import DTYPES, FLOAT_DTYPES, INT_DTYPES, array_order, arrays |
12 | 12 |
|
13 | 13 |
|
14 | 14 | @pytest.mark.parametrize( |
@@ -138,3 +138,31 @@ def test_replace_newaxis(dtype): |
138 | 138 | array = np.ones((2, 2), dtype=dtype)[..., np.newaxis] |
139 | 139 | result = bn.replace(array, 1, 2) |
140 | 140 | assert (result == 2).all().all() |
| 141 | + |
| 142 | + |
| 143 | +@pytest.mark.parametrize("dtype", DTYPES) |
| 144 | +def test_replace_view(dtype): |
| 145 | + """Test replace on non-contiguous view""" |
| 146 | + expected_array = np.arange(20, dtype=dtype) |
| 147 | + expected_view = expected_array[::2] |
| 148 | + bn.slow.replace(expected_view, 10, -1) |
| 149 | + array = np.arange(20, dtype=dtype) |
| 150 | + view = array[::2] |
| 151 | + bn.replace(view, 10, -1) |
| 152 | + assert_array_equal(view, expected_view) |
| 153 | + assert_array_equal(array, expected_array) |
| 154 | + |
| 155 | + |
| 156 | +@pytest.mark.parametrize("dtype", FLOAT_DTYPES) |
| 157 | +def test_replace_nan_view(dtype): |
| 158 | + """Test replace NaN on non-contiguous view""" |
| 159 | + expected_array = np.ones((4, 3, 2), dtype=dtype) |
| 160 | + expected_array[::2, :, 0] = np.nan |
| 161 | + expected_view = expected_array[:, :, 0] |
| 162 | + bn.slow.replace(expected_view, np.nan, 0) |
| 163 | + array = np.ones((4, 3, 2), dtype=dtype) |
| 164 | + array[::2, :, 0] = np.nan |
| 165 | + view = array[:, :, 0] |
| 166 | + bn.replace(view, np.nan, 0) |
| 167 | + assert_array_equal(view, expected_view) |
| 168 | + assert_array_equal(array, expected_array) |
0 commit comments