diff options
author | Julian Taylor <juliantaylor108@gmail.com> | 2018-04-27 19:38:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-27 19:38:14 +0200 |
commit | db552b5b6b37f2ff085b304751d7a2ebed26adc9 (patch) | |
tree | 86ef2cb1fa036a91c1e7e936a0bdf7bb2aec96cc | |
parent | 0a02ea2403f1d666ad186d8228cbe7d499b037c7 (diff) | |
parent | 92f85239dad607540a1fa3124e41c7b357caf7fe (diff) | |
download | numpy-db552b5b6b37f2ff085b304751d7a2ebed26adc9.tar.gz |
Merge pull request #10996 from adeak/docfix-stringio-unicode
DOC: Make doc examples using StringIO python2-3 compatible
-rw-r--r-- | numpy/lib/function_base.py | 4 | ||||
-rw-r--r-- | numpy/lib/npyio.py | 10 |
2 files changed, 7 insertions, 7 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 72beef471..a6e3e07d3 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1633,9 +1633,9 @@ def disp(mesg, device=None, linefeed=True): Besides ``sys.stdout``, a file-like object can also be used as it has both required methods: - >>> from StringIO import StringIO + >>> from io import StringIO >>> buf = StringIO() - >>> np.disp('"Display" in a file', device=buf) + >>> np.disp(u'"Display" in a file', device=buf) >>> buf.getvalue() '"Display" in a file\\n' diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 67585443b..97f50b5d8 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -859,18 +859,18 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, Examples -------- >>> from io import StringIO # StringIO behaves like a file object - >>> c = StringIO("0 1\\n2 3") + >>> c = StringIO(u"0 1\\n2 3") >>> np.loadtxt(c) array([[ 0., 1.], [ 2., 3.]]) - >>> d = StringIO("M 21 72\\nF 35 58") + >>> d = StringIO(u"M 21 72\\nF 35 58") >>> np.loadtxt(d, dtype={'names': ('gender', 'age', 'weight'), ... 'formats': ('S1', 'i4', 'f4')}) array([('M', 21, 72.0), ('F', 35, 58.0)], dtype=[('gender', '|S1'), ('age', '<i4'), ('weight', '<f4')]) - >>> c = StringIO("1,0,2\\n3,0,4") + >>> c = StringIO(u"1,0,2\\n3,0,4") >>> x, y = np.loadtxt(c, delimiter=',', usecols=(0, 2), unpack=True) >>> x array([ 1., 3.]) @@ -1632,7 +1632,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, Comma delimited file with mixed dtype - >>> s = StringIO("1,1.3,abcde") + >>> s = StringIO(u"1,1.3,abcde") >>> data = np.genfromtxt(s, dtype=[('myint','i8'),('myfloat','f8'), ... ('mystring','S5')], delimiter=",") >>> data @@ -1659,7 +1659,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, An example with fixed-width columns - >>> s = StringIO("11.3abcde") + >>> s = StringIO(u"11.3abcde") >>> data = np.genfromtxt(s, dtype=None, names=['intvar','fltvar','strvar'], ... delimiter=[1,3,5]) >>> data |