summaryrefslogtreecommitdiff
path: root/numpy/compat
diff options
context:
space:
mode:
authorBryan Van de Ven <bryan@Laptop-3.local>2012-02-20 11:32:57 -0600
committerCharles Harris <charlesr.harris@gmail.com>2012-03-03 14:24:12 -0700
commit91f87e1f613630ff0ad9864017f059afcd6e57f1 (patch)
treef4a75a8e3edc437479560b5ba953bba4abf6e45f /numpy/compat
parentd878ad9e8e2fd128eb6615f77574789f4ee5eb69 (diff)
downloadnumpy-91f87e1f613630ff0ad9864017f059afcd6e57f1.tar.gz
BUG: Fix ticket #1990.
When an array is created from a sequence of numeric (boolean, int, float, complex) and string (bytes, str, unicode) values, the resulting array type is string, but only the string values were being used to choose the string length, leading to truncation of data.
Diffstat (limited to 'numpy/compat')
-rw-r--r--numpy/compat/py3k.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/numpy/compat/py3k.py b/numpy/compat/py3k.py
index 001455de5..0a03929be 100644
--- a/numpy/compat/py3k.py
+++ b/numpy/compat/py3k.py
@@ -13,32 +13,45 @@ if sys.version_info[0] >= 3:
import io
bytes = bytes
unicode = str
- asunicode = str
+
+ def asunicode(s):
+ if isinstance(s, bytes):
+ return s.decode('latin1')
+ return str(s)
+
def asbytes(s):
if isinstance(s, bytes):
return s
- return s.encode('latin1')
+ return str(s).encode('latin1')
+
def asstr(s):
- if isinstance(s, str):
- return s
- return s.decode('latin1')
+ if isinstance(s, bytes):
+ return s.decode('latin1')
+ return str(s)
+
def isfileobj(f):
return isinstance(f, (io.FileIO, io.BufferedReader))
+
def open_latin1(filename, mode='r'):
return open(filename, mode=mode, encoding='iso-8859-1')
+
strchar = 'U'
+
else:
bytes = str
unicode = unicode
asbytes = str
asstr = str
strchar = 'S'
+
def isfileobj(f):
return isinstance(f, file)
+
def asunicode(s):
if isinstance(s, unicode):
return s
- return s.decode('ascii')
+ return str(s).decode('ascii')
+
def open_latin1(filename, mode='r'):
return open(filename, mode=mode)