Author: Brian Kearns <[email protected]>
Branch:
Changeset: r69410:89a5865820d1
Date: 2014-02-25 03:52 -0500
http://bitbucket.org/pypy/pypy/changeset/89a5865820d1/
Log: fix a char dtype case
diff --git a/pypy/module/micronumpy/interp_dtype.py
b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -587,10 +587,8 @@
except ValueError:
raise oefmt(space.w_TypeError, "data type not understood")
if char == NPY.CHARLTR:
- char = NPY.STRINGLTR
- size = 1
-
- if char == NPY.STRINGLTR:
+ return new_string_dtype(space, 1, NPY.CHARLTR)
+ elif char == NPY.STRINGLTR:
return new_string_dtype(space, size)
elif char == NPY.UNICODELTR:
return new_unicode_dtype(space, size)
@@ -599,13 +597,13 @@
assert False
-def new_string_dtype(space, size):
+def new_string_dtype(space, size, char=NPY.STRINGLTR):
return W_Dtype(
types.StringType(),
elsize=size,
num=NPY.STRING,
kind=NPY.STRINGLTR,
- char=NPY.STRINGLTR,
+ char=char,
w_box_type=space.gettypefor(interp_boxes.W_StringBox),
)
diff --git a/pypy/module/micronumpy/test/test_dtypes.py
b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -891,6 +891,11 @@
assert dtype('void').byteorder == '|'
assert dtype((int, 2)).byteorder == '|'
assert dtype(np.generic).str == '|V0'
+ d = dtype(np.character)
+ assert d.num == 18
+ assert d.char == 'S'
+ assert d.kind == 'S'
+ assert d.str == '|S0'
def test_dtype_str(self):
from numpypy import dtype
@@ -1055,9 +1060,15 @@
assert isinstance(u, unicode)
def test_character_dtype(self):
+ import numpy as np
from numpypy import array, character
x = array([["A", "B"], ["C", "D"]], character)
assert (x == [["A", "B"], ["C", "D"]]).all()
+ d = np.dtype('c')
+ assert d.num == 18
+ assert d.char == 'c'
+ assert d.kind == 'S'
+ assert d.str == '|S1'
class AppTestRecordDtypes(BaseNumpyAppTest):
spaceconfig = dict(usemodules=["micronumpy", "struct", "binascii"])
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit