|
11 | 11 |
|
12 | 12 | from unittest import mock
|
13 | 13 |
|
| 14 | +import dask.array as da |
14 | 15 | import numpy as np
|
15 | 16 | import numpy.ma as ma
|
16 | 17 |
|
@@ -147,23 +148,35 @@ def test_masked_2d_multi(self):
|
147 | 148 | data, axis, percent, expected, mdtol=mdtol, approx=True
|
148 | 149 | )
|
149 | 150 |
|
150 |
| - @mock.patch("scipy.stats.mstats.mquantiles") |
| 151 | + @mock.patch("scipy.stats.mstats.mquantiles", return_value=[2, 4]) |
151 | 152 | def test_default_kwargs_passed(self, mocked_mquantiles):
|
152 | 153 | data = np.arange(5)
|
153 |
| - percent = 50 |
| 154 | + percent = [42, 75] |
154 | 155 | axis = 0
|
| 156 | + if self.lazy: |
| 157 | + data = as_lazy_data(data) |
| 158 | + |
155 | 159 | self.agg_method(data, axis=axis, percent=percent)
|
| 160 | + |
| 161 | + # Trigger calculation for lazy case. |
| 162 | + as_concrete_data(data) |
156 | 163 | for key in ["alphap", "betap"]:
|
157 | 164 | self.assertEqual(mocked_mquantiles.call_args.kwargs[key], 1)
|
158 | 165 |
|
159 | 166 | @mock.patch("scipy.stats.mstats.mquantiles")
|
160 | 167 | def test_chosen_kwargs_passed(self, mocked_mquantiles):
|
161 | 168 | data = np.arange(5)
|
162 |
| - percent = 50 |
| 169 | + percent = [42, 75] |
163 | 170 | axis = 0
|
| 171 | + if self.lazy: |
| 172 | + data = as_lazy_data(data) |
| 173 | + |
164 | 174 | self.agg_method(
|
165 | 175 | data, axis=axis, percent=percent, alphap=0.6, betap=0.5
|
166 | 176 | )
|
| 177 | + |
| 178 | + # Trigger calculation for lazy case. |
| 179 | + as_concrete_data(data) |
167 | 180 | for key, val in zip(["alphap", "betap"], [0.6, 0.5]):
|
168 | 181 | self.assertEqual(mocked_mquantiles.call_args.kwargs[key], val)
|
169 | 182 |
|
@@ -200,11 +213,18 @@ def test_masked(self):
|
200 | 213 | data, axis=0, percent=50, fast_percentile_method=True
|
201 | 214 | )
|
202 | 215 |
|
| 216 | + @mock.patch("numpy.percentile") |
| 217 | + def test_numpy_percentile_called(self, mocked_percentile): |
| 218 | + # Basic check that numpy.percentile is called. |
| 219 | + data = np.arange(5) |
| 220 | + self.agg_method(data, axis=0, percent=42, fast_percentile_method=True) |
| 221 | + mocked_percentile.assert_called_once() |
| 222 | + |
203 | 223 |
|
204 | 224 | class MultiAxisMixin:
|
205 | 225 | """
|
206 | 226 | Tests for axis passed as a tuple. Only relevant for lazy aggregation since
|
207 |
| - axis is always specified as int for real aggregation. |
| 227 | + axis is always specified asax int for real aggregation. |
208 | 228 |
|
209 | 229 | """
|
210 | 230 |
|
@@ -269,6 +289,18 @@ def test_masked(self):
|
269 | 289 | with self.assertRaisesRegex(TypeError, emsg):
|
270 | 290 | as_concrete_data(actual)
|
271 | 291 |
|
| 292 | + @mock.patch("numpy.percentile", return_value=np.array([2, 4])) |
| 293 | + def test_numpy_percentile_called(self, mocked_percentile): |
| 294 | + # Basic check that numpy.percentile is called. |
| 295 | + data = da.arange(5) |
| 296 | + result = self.agg_method( |
| 297 | + data, axis=0, percent=[42, 75], fast_percentile_method=True |
| 298 | + ) |
| 299 | + |
| 300 | + self.assertTrue(is_lazy_data(result)) |
| 301 | + as_concrete_data(result) |
| 302 | + mocked_percentile.assert_called() |
| 303 | + |
272 | 304 |
|
273 | 305 | class Test_lazy_aggregate(
|
274 | 306 | tests.IrisTest, AggregateMixin, MaskedAggregateMixin, MultiAxisMixin
|
|
0 commit comments