10
10
from __future__ import division , print_function
11
11
12
12
import sys
13
+ import re
13
14
import warnings
14
15
import gzip
15
16
from collections import OrderedDict
41
42
#: file-like classes known to hold compressed data
42
43
COMPRESSED_FILE_LIKES = (gzip .GzipFile , BZ2File )
43
44
45
+ _OVERFLOW_FILTER = (
46
+ 'ignore' ,
47
+ re .compile (r'.*overflow.*' , re .IGNORECASE | re .UNICODE ),
48
+ RuntimeWarning ,
49
+ re .compile (r'' , re .UNICODE ),
50
+ 0 )
51
+
44
52
45
53
class Recoder (object ):
46
54
''' class to return canonical code(s) from code or aliases
@@ -1334,7 +1342,9 @@ def _ftype4scaled_finite(tst_arr, slope, inter, direction='read',
1334
1342
tst_arr = np .atleast_1d (tst_arr )
1335
1343
slope = np .atleast_1d (slope )
1336
1344
inter = np .atleast_1d (inter )
1337
- warnings .filterwarnings ('ignore' , '.*overflow.*' , RuntimeWarning )
1345
+ warnings .filters .insert (0 , _OVERFLOW_FILTER )
1346
+ getattr (warnings , '_filters_mutated' , lambda : None )() # PY2
1347
+ # warnings._filters_mutated() # PY3
1338
1348
try :
1339
1349
for ftype in OK_FLOATS [def_ind :]:
1340
1350
tst_trans = tst_arr .copy ()
@@ -1353,7 +1363,12 @@ def _ftype4scaled_finite(tst_arr, slope, inter, direction='read',
1353
1363
if np .all (np .isfinite (tst_trans )):
1354
1364
return ftype
1355
1365
finally :
1356
- warnings .filters .pop (0 )
1366
+ try :
1367
+ warnings .filters .remove (_OVERFLOW_FILTER )
1368
+ getattr (warnings , '_filters_mutated' , lambda : None )() # PY2
1369
+ # warnings._filters_mutated() # PY3
1370
+ except ValueError :
1371
+ pass
1357
1372
raise ValueError ('Overflow using highest floating point type' )
1358
1373
1359
1374
0 commit comments