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

Skip to content

Commit ba58718

Browse files
cgohlkecertik
authored andcommitted
Fix unicode tests for flexible string representation on Python 3.3
1 parent c4c169c commit ba58718

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

numpy/core/tests/test_unicode.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@
55
from numpy.compat import asbytes
66

77
# Guess the UCS length for this python interpreter
8-
if sys.version_info[0] >= 3:
8+
if sys.version_info[:2] >= (3, 3):
9+
# Python 3.3 uses a flexible string representation
10+
ucs4 = False
11+
def buffer_length(arr):
12+
if isinstance(arr, unicode):
13+
arr = str(arr)
14+
return (sys.getsizeof(arr+"a") - sys.getsizeof(arr)) * len(arr)
15+
v = memoryview(arr)
16+
if v.shape is None:
17+
return len(v) * v.itemsize
18+
else:
19+
return prod(v.shape) * v.itemsize
20+
elif sys.version_info[0] >= 3:
921
import array as _array
1022
ucs4 = (_array.array('u').itemsize == 4)
1123
def buffer_length(arr):

0 commit comments

Comments
 (0)