Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dc46a49

Browse files
committed
Add workaround for numpy savetxt fmt issue
1 parent 2b9f126 commit dc46a49

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

pytest_arraydiff/plugin.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737
import tempfile
3838
import warnings
3939

40-
from six import add_metaclass, PY2
40+
import six
4141
from six.moves.urllib.request import urlopen
4242

4343
import pytest
4444
import numpy as np
4545

4646

47-
if PY2:
47+
if six.PY2:
4848
def abstractstaticmethod(func):
4949
return func
5050
def abstractclassmethod(func):
@@ -54,7 +54,7 @@ def abstractclassmethod(func):
5454
abstractclassmethod = abc.abstractclassmethod
5555

5656

57-
@add_metaclass(abc.ABCMeta)
57+
@six.add_metaclass(abc.ABCMeta)
5858
class BaseDiff(object):
5959

6060
@abstractstaticmethod
@@ -136,8 +136,15 @@ def read(filename):
136136

137137
@staticmethod
138138
def write(filename, data, **kwargs):
139-
if 'fmt' not in kwargs:
140-
kwargs['fmt'] = '%g'
139+
fmt = kwargs.get('fmt', '%g')
140+
# Workaround for a known issue in `numpy.savetxt` for the `fmt` argument:
141+
# https://github.com/numpy/numpy/pull/4053#issuecomment-263808221
142+
# Convert `unicode` to `str` (i.e. bytes) on Python 2
143+
if six.PY2 and isinstance(fmt, six.text_type):
144+
fmt = fmt.encode('ascii')
145+
146+
kwargs['fmt'] = fmt
147+
141148
return np.savetxt(filename, data, **kwargs)
142149

143150

0 commit comments

Comments
 (0)