@@ -38,8 +38,8 @@ def test_colinear_pca():
38
38
a = mlab .PCA ._get_colinear ()
39
39
pca = mlab .PCA (a )
40
40
41
- assert_allclose (pca .fracs [2 :], 0. , atol = 1e-8 )
42
- assert_allclose (pca .Y [:, 2 :], 0. , atol = 1e-8 )
41
+ assert_allclose (pca .fracs [2 :], 0. , atol = 1e-8 )
42
+ assert_allclose (pca .Y [:, 2 :], 0. , atol = 1e-8 )
43
43
44
44
45
45
@pytest .mark .parametrize ('input' , [
@@ -82,9 +82,9 @@ def test_prctile(input, percentile):
82
82
def test_logspace (xmin , xmax , N ):
83
83
with pytest .warns (MatplotlibDeprecationWarning ):
84
84
res = mlab .logspace (xmin , xmax , N )
85
- targ = np .logspace (np .log10 (xmin ), np .log10 (xmax ), N )
86
- assert_allclose (targ , res )
87
- assert res .size == N
85
+ targ = np .logspace (np .log10 (xmin ), np .log10 (xmax ), N )
86
+ assert_allclose (targ , res )
87
+ assert res .size == N
88
88
89
89
90
90
class TestStride (object ):
@@ -222,43 +222,43 @@ def tempcsv():
222
222
223
223
224
224
def test_recarray_csv_roundtrip (tempcsv ):
225
+ expected = np .recarray ((99 ,),
226
+ [(str ('x' ), float ),
227
+ (str ('y' ), float ),
228
+ (str ('t' ), float )])
229
+ # initialising all values: uninitialised memory sometimes produces
230
+ # floats that do not round-trip to string and back.
231
+ expected ['x' ][:] = np .linspace (- 1e9 , - 1 , 99 )
232
+ expected ['y' ][:] = np .linspace (1 , 1e9 , 99 )
233
+ expected ['t' ][:] = np .linspace (0 , 0.01 , 99 )
225
234
with pytest .warns (MatplotlibDeprecationWarning ):
226
- expected = np .recarray ((99 ,),
227
- [(str ('x' ), float ),
228
- (str ('y' ), float ),
229
- (str ('t' ), float )])
230
- # initialising all values: uninitialised memory sometimes produces
231
- # floats that do not round-trip to string and back.
232
- expected ['x' ][:] = np .linspace (- 1e9 , - 1 , 99 )
233
- expected ['y' ][:] = np .linspace (1 , 1e9 , 99 )
234
- expected ['t' ][:] = np .linspace (0 , 0.01 , 99 )
235
-
236
235
mlab .rec2csv (expected , tempcsv )
237
236
tempcsv .seek (0 )
238
237
actual = mlab .csv2rec (tempcsv )
239
238
240
- assert_allclose (expected ['x' ], actual ['x' ])
241
- assert_allclose (expected ['y' ], actual ['y' ])
242
- assert_allclose (expected ['t' ], actual ['t' ])
239
+ assert_allclose (expected ['x' ], actual ['x' ])
240
+ assert_allclose (expected ['y' ], actual ['y' ])
241
+ assert_allclose (expected ['t' ], actual ['t' ])
243
242
244
243
245
244
def test_rec2csv_bad_shape_ValueError (tempcsv ):
246
- with pytest .warns (MatplotlibDeprecationWarning ):
247
- bad = np .recarray ((99 , 4 ), [(str ('x' ), float ),
248
- (str ('y' ), float )])
245
+ bad = np .recarray ((99 , 4 ), [(str ('x' ), float ),
246
+ (str ('y' ), float )])
249
247
250
- # the bad recarray should trigger a ValueError for having ndim > 1.
248
+ # the bad recarray should trigger a ValueError for having ndim > 1.
249
+ with pytest .warns (MatplotlibDeprecationWarning ):
251
250
with pytest .raises (ValueError ):
252
251
mlab .rec2csv (bad , tempcsv )
253
252
254
253
255
254
def test_csv2rec_names_with_comments (tempcsv ):
255
+
256
+ tempcsv .write ('# comment\n 1,2,3\n 4,5,6\n ' )
257
+ tempcsv .seek (0 )
256
258
with pytest .warns (MatplotlibDeprecationWarning ):
257
- tempcsv .write ('# comment\n 1,2,3\n 4,5,6\n ' )
258
- tempcsv .seek (0 )
259
259
array = mlab .csv2rec (tempcsv , names = 'a,b,c' )
260
- assert len (array ) == 2
261
- assert len (array .dtype ) == 3
260
+ assert len (array ) == 2
261
+ assert len (array .dtype ) == 3
262
262
263
263
264
264
@pytest .mark .parametrize ('input, kwargs' , [
@@ -282,31 +282,31 @@ def test_csv2rec_names_with_comments(tempcsv):
282
282
{'yearfirst' : True }),
283
283
], ids = ['usdate' , 'dayfirst' , 'yearfirst' ])
284
284
def test_csv2rec_dates (tempcsv , input , kwargs ):
285
+ tempcsv .write (input )
286
+ expected = [datetime .datetime (2014 , 1 , 11 , 0 , 0 ),
287
+ datetime .datetime (1976 , 3 , 5 , 0 , 0 , 1 ),
288
+ datetime .datetime (1983 , 7 , 9 , 17 , 17 , 34 ),
289
+ datetime .datetime (2054 , 6 , 20 , 14 , 31 , 45 ),
290
+ datetime .datetime (2000 , 10 , 31 , 11 , 50 , 23 )]
291
+ tempcsv .seek (0 )
285
292
with pytest .warns (MatplotlibDeprecationWarning ):
286
- tempcsv .write (input )
287
- expected = [datetime .datetime (2014 , 1 , 11 , 0 , 0 ),
288
- datetime .datetime (1976 , 3 , 5 , 0 , 0 , 1 ),
289
- datetime .datetime (1983 , 7 , 9 , 17 , 17 , 34 ),
290
- datetime .datetime (2054 , 6 , 20 , 14 , 31 , 45 ),
291
- datetime .datetime (2000 , 10 , 31 , 11 , 50 , 23 )]
292
- tempcsv .seek (0 )
293
293
array = mlab .csv2rec (tempcsv , names = 'a' , ** kwargs )
294
- assert_array_equal (array ['a' ].tolist (), expected )
294
+ assert_array_equal (array ['a' ].tolist (), expected )
295
295
296
296
297
297
def test_rec2txt_basic ():
298
+ # str() calls around field names necessary b/c as of numpy 1.11
299
+ # dtype doesn't like unicode names (caused by unicode_literals import)
300
+ a = np .array ([(1.0 , 2 , 'foo' , 'bing' ),
301
+ (2.0 , 3 , 'bar' , 'blah' )],
302
+ dtype = np .dtype ([(str ('x' ), np .float32 ),
303
+ (str ('y' ), np .int8 ),
304
+ (str ('s' ), str , 3 ),
305
+ (str ('s2' ), str , 4 )]))
306
+ truth = (' x y s s2\n '
307
+ ' 1.000 2 foo bing \n '
308
+ ' 2.000 3 bar blah ' ).splitlines ()
298
309
with pytest .warns (MatplotlibDeprecationWarning ):
299
- # str() calls around field names necessary b/c as of numpy 1.11
300
- # dtype doesn't like unicode names (caused by unicode_literals import)
301
- a = np .array ([(1.0 , 2 , 'foo' , 'bing' ),
302
- (2.0 , 3 , 'bar' , 'blah' )],
303
- dtype = np .dtype ([(str ('x' ), np .float32 ),
304
- (str ('y' ), np .int8 ),
305
- (str ('s' ), str , 3 ),
306
- (str ('s2' ), str , 4 )]))
307
- truth = (' x y s s2\n '
308
- ' 1.000 2 foo bing \n '
309
- ' 2.000 3 bar blah ' ).splitlines ()
310
310
assert mlab .rec2txt (a ).splitlines () == truth
311
311
312
312
@@ -2145,72 +2145,77 @@ def test_psd_windowarray_equal(self):
2145
2145
2146
2146
2147
2147
def test_griddata_linear ():
2148
+ # z is a linear function of x and y.
2149
+ def get_z (x , y ):
2150
+ return 3.0 * x - y
2151
+
2152
+ # Passing 1D xi and yi arrays to griddata.
2153
+ x = np .asarray ([0.0 , 1.0 , 0.0 , 1.0 , 0.5 ])
2154
+ y = np .asarray ([0.0 , 0.0 , 1.0 , 1.0 , 0.5 ])
2155
+ z = get_z (x , y )
2156
+ xi = [0.2 , 0.4 , 0.6 , 0.8 ]
2157
+ yi = [0.1 , 0.3 , 0.7 , 0.9 ]
2148
2158
with pytest .warns (MatplotlibDeprecationWarning ):
2149
- # z is a linear function of x and y.
2150
- def get_z (x , y ):
2151
- return 3.0 * x - y
2152
-
2153
- # Passing 1D xi and yi arrays to griddata.
2154
- x = np .asarray ([0.0 , 1.0 , 0.0 , 1.0 , 0.5 ])
2155
- y = np .asarray ([0.0 , 0.0 , 1.0 , 1.0 , 0.5 ])
2156
- z = get_z (x , y )
2157
- xi = [0.2 , 0.4 , 0.6 , 0.8 ]
2158
- yi = [0.1 , 0.3 , 0.7 , 0.9 ]
2159
2159
zi = mlab .griddata (x , y , z , xi , yi , interp = 'linear' )
2160
- xi , yi = np .meshgrid (xi , yi )
2161
- np .testing .assert_array_almost_equal (zi , get_z (xi , yi ))
2160
+ xi , yi = np .meshgrid (xi , yi )
2161
+ np .testing .assert_array_almost_equal (zi , get_z (xi , yi ))
2162
2162
2163
- # Passing 2D xi and yi arrays to griddata.
2163
+ # Passing 2D xi and yi arrays to griddata.
2164
+ with pytest .warns (MatplotlibDeprecationWarning ):
2164
2165
zi = mlab .griddata (x , y , z , xi , yi , interp = 'linear' )
2165
- np .testing .assert_array_almost_equal (zi , get_z (xi , yi ))
2166
+ np .testing .assert_array_almost_equal (zi , get_z (xi , yi ))
2166
2167
2167
- # Masking z array.
2168
- z_masked = np .ma .array (z , mask = [False , False , False , True , False ])
2169
- correct_zi_masked = np .ma .masked_where (xi + yi > 1.0 , get_z (xi , yi ))
2168
+ # Masking z array.
2169
+ z_masked = np .ma .array (z , mask = [False , False , False , True , False ])
2170
+ correct_zi_masked = np .ma .masked_where (xi + yi > 1.0 , get_z (xi , yi ))
2171
+ with pytest .warns (MatplotlibDeprecationWarning ):
2170
2172
zi = mlab .griddata (x , y , z_masked , xi , yi , interp = 'linear' )
2171
- matest .assert_array_almost_equal (zi , correct_zi_masked )
2172
- np .testing .assert_array_equal (np .ma .getmask (zi ),
2173
- np .ma .getmask (correct_zi_masked ))
2173
+ matest .assert_array_almost_equal (zi , correct_zi_masked )
2174
+ np .testing .assert_array_equal (np .ma .getmask (zi ),
2175
+ np .ma .getmask (correct_zi_masked ))
2174
2176
2175
2177
2176
2178
@pytest .mark .xfail (not HAS_NATGRID , reason = 'natgrid not installed' )
2177
2179
def test_griddata_nn ():
2180
+ # z is a linear function of x and y.
2181
+ def get_z (x , y ):
2182
+ return 3.0 * x - y
2183
+
2184
+ # Passing 1D xi and yi arrays to griddata.
2185
+ x = np .asarray ([0.0 , 1.0 , 0.0 , 1.0 , 0.5 ])
2186
+ y = np .asarray ([0.0 , 0.0 , 1.0 , 1.0 , 0.5 ])
2187
+ z = get_z (x , y )
2188
+ xi = [0.2 , 0.4 , 0.6 , 0.8 ]
2189
+ yi = [0.1 , 0.3 , 0.7 , 0.9 ]
2190
+ correct_zi = [[0.49999252 , 1.0999978 , 1.7000030 , 2.3000080 ],
2191
+ [0.29999208 , 0.8999978 , 1.5000029 , 2.1000059 ],
2192
+ [- 0.1000099 , 0.4999943 , 1.0999964 , 1.6999979 ],
2193
+ [- 0.3000128 , 0.2999894 , 0.8999913 , 1.4999933 ]]
2178
2194
with pytest .warns (MatplotlibDeprecationWarning ):
2179
- # z is a linear function of x and y.
2180
- def get_z (x , y ):
2181
- return 3.0 * x - y
2182
-
2183
- # Passing 1D xi and yi arrays to griddata.
2184
- x = np .asarray ([0.0 , 1.0 , 0.0 , 1.0 , 0.5 ])
2185
- y = np .asarray ([0.0 , 0.0 , 1.0 , 1.0 , 0.5 ])
2186
- z = get_z (x , y )
2187
- xi = [0.2 , 0.4 , 0.6 , 0.8 ]
2188
- yi = [0.1 , 0.3 , 0.7 , 0.9 ]
2189
- correct_zi = [[0.49999252 , 1.0999978 , 1.7000030 , 2.3000080 ],
2190
- [0.29999208 , 0.8999978 , 1.5000029 , 2.1000059 ],
2191
- [- 0.1000099 , 0.4999943 , 1.0999964 , 1.6999979 ],
2192
- [- 0.3000128 , 0.2999894 , 0.8999913 , 1.4999933 ]]
2193
2195
zi = mlab .griddata (x , y , z , xi , yi , interp = 'nn' )
2194
- np .testing .assert_array_almost_equal (zi , correct_zi , 5 )
2196
+ np .testing .assert_array_almost_equal (zi , correct_zi , 5 )
2195
2197
2198
+ with pytest .warns (MatplotlibDeprecationWarning ):
2196
2199
# Decreasing xi or yi should raise ValueError.
2197
2200
with pytest .raises (ValueError ):
2198
2201
mlab .griddata (x , y , z , xi [::- 1 ], yi , interp = 'nn' )
2199
2202
with pytest .raises (ValueError ):
2200
2203
mlab .griddata (x , y , z , xi , yi [::- 1 ], interp = 'nn' )
2201
2204
2202
- # Passing 2D xi and yi arrays to griddata.
2203
- xi , yi = np .meshgrid (xi , yi )
2205
+ # Passing 2D xi and yi arrays to griddata.
2206
+ xi , yi = np .meshgrid (xi , yi )
2207
+ with pytest .warns (MatplotlibDeprecationWarning ):
2204
2208
zi = mlab .griddata (x , y , z , xi , yi , interp = 'nn' )
2205
- np .testing .assert_array_almost_equal (zi , correct_zi , 5 )
2209
+ np .testing .assert_array_almost_equal (zi , correct_zi , 5 )
2206
2210
2207
- # Masking z array.
2208
- z_masked = np .ma .array (z , mask = [False , False , False , True , False ])
2209
- correct_zi_masked = np .ma .masked_where (xi + yi > 1.0 , correct_zi )
2211
+ # Masking z array.
2212
+ z_masked = np .ma .array (z , mask = [False , False , False , True , False ])
2213
+ correct_zi_masked = np .ma .masked_where (xi + yi > 1.0 , correct_zi )
2214
+ with pytest .warns (MatplotlibDeprecationWarning ):
2210
2215
zi = mlab .griddata (x , y , z_masked , xi , yi , interp = 'nn' )
2211
- np .testing .assert_array_almost_equal (zi , correct_zi_masked , 5 )
2212
- np .testing .assert_array_equal (np .ma .getmask (zi ),
2213
- np .ma .getmask (correct_zi_masked ))
2216
+ np .testing .assert_array_almost_equal (zi , correct_zi_masked , 5 )
2217
+ np .testing .assert_array_equal (np .ma .getmask (zi ),
2218
+ np .ma .getmask (correct_zi_masked ))
2214
2219
2215
2220
2216
2221
#*****************************************************************
@@ -2411,22 +2416,26 @@ def test_contiguous_regions():
2411
2416
# Starts and ends with True
2412
2417
mask = [True ]* a + [False ]* b + [True ]* c
2413
2418
expected = [(0 , a ), (a + b , a + b + c )]
2414
- assert mlab .contiguous_regions (mask ) == expected
2419
+ with pytest .warns (MatplotlibDeprecationWarning ):
2420
+ assert mlab .contiguous_regions (mask ) == expected
2415
2421
d , e = 6 , 7
2416
2422
# Starts with True ends with False
2417
2423
mask = mask + [False ]* e
2418
- assert mlab .contiguous_regions (mask ) == expected
2424
+ with pytest .warns (MatplotlibDeprecationWarning ):
2425
+ assert mlab .contiguous_regions (mask ) == expected
2419
2426
# Starts with False ends with True
2420
2427
mask = [False ]* d + mask [:- e ]
2421
2428
expected = [(d , d + a ), (d + a + b , d + a + b + c )]
2422
- assert mlab .contiguous_regions (mask ) == expected
2429
+ with pytest .warns (MatplotlibDeprecationWarning ):
2430
+ assert mlab .contiguous_regions (mask ) == expected
2423
2431
# Starts and ends with False
2424
2432
mask = mask + [False ]* e
2425
- assert mlab .contiguous_regions (mask ) == expected
2426
- # No True in mask
2427
- assert mlab .contiguous_regions ([False ]* 5 ) == []
2428
- # Empty mask
2429
- assert mlab .contiguous_regions ([]) == []
2433
+ with pytest .warns (MatplotlibDeprecationWarning ):
2434
+ assert mlab .contiguous_regions (mask ) == expected
2435
+ # No True in mask
2436
+ assert mlab .contiguous_regions ([False ]* 5 ) == []
2437
+ # Empty mask
2438
+ assert mlab .contiguous_regions ([]) == []
2430
2439
2431
2440
2432
2441
def test_psd_onesided_norm ():
0 commit comments