15
15
16
16
import matplotlib .mlab as mlab
17
17
import matplotlib .cbook as cbook
18
+ from matplotlib .cbook .deprecation import MatplotlibDeprecationWarning
18
19
19
20
20
21
try :
24
25
HAS_NATGRID = False
25
26
26
27
28
+ '''
29
+ A lot of mlab.py has been deprecated in Matplotlib 2.2 and is scheduled for
30
+ removal in the future. The tests that use deprecated methods have a block
31
+ to catch the deprecation warning, and can be removed with the mlab code is
32
+ removed.
33
+ '''
34
+
35
+
27
36
def test_colinear_pca ():
28
- a = mlab .PCA ._get_colinear ()
29
- pca = mlab .PCA (a )
37
+ with pytest .warns (MatplotlibDeprecationWarning ):
38
+ a = mlab .PCA ._get_colinear ()
39
+ pca = mlab .PCA (a )
30
40
31
- assert_allclose (pca .fracs [2 :], 0. , atol = 1e-8 )
32
- 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 )
33
43
34
44
35
45
@pytest .mark .parametrize ('input' , [
@@ -53,8 +63,9 @@ def test_colinear_pca():
53
63
[0 , 75 , 100 ],
54
64
])
55
65
def test_prctile (input , percentile ):
56
- assert_allclose (mlab .prctile (input , percentile ),
57
- np .percentile (input , percentile ))
66
+ with pytest .warns (MatplotlibDeprecationWarning ):
67
+ assert_allclose (mlab .prctile (input , percentile ),
68
+ np .percentile (input , percentile ))
58
69
59
70
60
71
@pytest .mark .parametrize ('xmin, xmax, N' , [
@@ -69,10 +80,11 @@ def test_prctile(input, percentile):
69
80
'single' ,
70
81
])
71
82
def test_logspace (xmin , xmax , N ):
72
- res = mlab .logspace (xmin , xmax , N )
73
- targ = np .logspace (np .log10 (xmin ), np .log10 (xmax ), N )
74
- assert_allclose (targ , res )
75
- assert res .size == N
83
+ with pytest .warns (MatplotlibDeprecationWarning ):
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
76
88
77
89
78
90
class TestStride (object ):
@@ -210,40 +222,43 @@ def tempcsv():
210
222
211
223
212
224
def test_recarray_csv_roundtrip (tempcsv ):
213
- expected = np .recarray ((99 ,),
214
- [(str ('x' ), float ),
215
- (str ('y' ), float ),
216
- (str ('t' ), float )])
217
- # initialising all values: uninitialised memory sometimes produces
218
- # floats that do not round-trip to string and back.
219
- expected ['x' ][:] = np .linspace (- 1e9 , - 1 , 99 )
220
- expected ['y' ][:] = np .linspace (1 , 1e9 , 99 )
221
- expected ['t' ][:] = np .linspace (0 , 0.01 , 99 )
222
-
223
- mlab .rec2csv (expected , tempcsv )
224
- tempcsv .seek (0 )
225
- actual = mlab .csv2rec (tempcsv )
226
-
227
- assert_allclose (expected ['x' ], actual ['x' ])
228
- assert_allclose (expected ['y' ], actual ['y' ])
229
- assert_allclose (expected ['t' ], actual ['t' ])
225
+ 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
+ mlab .rec2csv (expected , tempcsv )
237
+ tempcsv .seek (0 )
238
+ actual = mlab .csv2rec (tempcsv )
239
+
240
+ assert_allclose (expected ['x' ], actual ['x' ])
241
+ assert_allclose (expected ['y' ], actual ['y' ])
242
+ assert_allclose (expected ['t' ], actual ['t' ])
230
243
231
244
232
245
def test_rec2csv_bad_shape_ValueError (tempcsv ):
233
- bad = np .recarray ((99 , 4 ), [(str ('x' ), float ),
234
- (str ('y' ), float )])
246
+ with pytest .warns (MatplotlibDeprecationWarning ):
247
+ bad = np .recarray ((99 , 4 ), [(str ('x' ), float ),
248
+ (str ('y' ), float )])
235
249
236
- # the bad recarray should trigger a ValueError for having ndim > 1.
237
- with pytest .raises (ValueError ):
238
- mlab .rec2csv (bad , tempcsv )
250
+ # the bad recarray should trigger a ValueError for having ndim > 1.
251
+ with pytest .raises (ValueError ):
252
+ mlab .rec2csv (bad , tempcsv )
239
253
240
254
241
255
def test_csv2rec_names_with_comments (tempcsv ):
242
- tempcsv .write ('# comment\n 1,2,3\n 4,5,6\n ' )
243
- tempcsv .seek (0 )
244
- array = mlab .csv2rec (tempcsv , names = 'a,b,c' )
245
- assert len (array ) == 2
246
- assert len (array .dtype ) == 3
256
+ with pytest .warns (MatplotlibDeprecationWarning ):
257
+ tempcsv .write ('# comment\n 1,2,3\n 4,5,6\n ' )
258
+ tempcsv .seek (0 )
259
+ array = mlab .csv2rec (tempcsv , names = 'a,b,c' )
260
+ assert len (array ) == 2
261
+ assert len (array .dtype ) == 3
247
262
248
263
249
264
@pytest .mark .parametrize ('input, kwargs' , [
@@ -267,30 +282,32 @@ def test_csv2rec_names_with_comments(tempcsv):
267
282
{'yearfirst' : True }),
268
283
], ids = ['usdate' , 'dayfirst' , 'yearfirst' ])
269
284
def test_csv2rec_dates (tempcsv , input , kwargs ):
270
- tempcsv .write (input )
271
- expected = [datetime .datetime (2014 , 1 , 11 , 0 , 0 ),
272
- datetime .datetime (1976 , 3 , 5 , 0 , 0 , 1 ),
273
- datetime .datetime (1983 , 7 , 9 , 17 , 17 , 34 ),
274
- datetime .datetime (2054 , 6 , 20 , 14 , 31 , 45 ),
275
- datetime .datetime (2000 , 10 , 31 , 11 , 50 , 23 )]
276
- tempcsv .seek (0 )
277
- array = mlab .csv2rec (tempcsv , names = 'a' , ** kwargs )
278
- assert_array_equal (array ['a' ].tolist (), expected )
285
+ 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
+ array = mlab .csv2rec (tempcsv , names = 'a' , ** kwargs )
294
+ assert_array_equal (array ['a' ].tolist (), expected )
279
295
280
296
281
297
def test_rec2txt_basic ():
282
- # str() calls around field names necessary b/c as of numpy 1.11
283
- # dtype doesn't like unicode names (caused by unicode_literals import)
284
- a = np .array ([(1.0 , 2 , 'foo' , 'bing' ),
285
- (2.0 , 3 , 'bar' , 'blah' )],
286
- dtype = np .dtype ([(str ('x' ), np .float32 ),
287
- (str ('y' ), np .int8 ),
288
- (str ('s' ), str , 3 ),
289
- (str ('s2' ), str , 4 )]))
290
- truth = (' x y s s2\n '
291
- ' 1.000 2 foo bing \n '
292
- ' 2.000 3 bar blah ' ).splitlines ()
293
- assert mlab .rec2txt (a ).splitlines () == truth
298
+ 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
+ assert mlab .rec2txt (a ).splitlines () == truth
294
311
295
312
296
313
class TestWindow (object ):
0 commit comments