[pypy-commit] pypy default: oct/hex for numpy scalars
bdkearns
noreply at buildbot.pypy.org
Wed Dec 11 22:06:48 CET 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r68409:fbcabd23ed43
Date: 2013-12-11 16:04 -0500
http://bitbucket.org/pypy/pypy/changeset/fbcabd23ed43/
Log: oct/hex for numpy scalars
diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -163,6 +163,12 @@
assert isinstance(box, W_Float64Box)
return space.wrap(box.value)
+ def descr_oct(self, space):
+ return space.oct(self.descr_int(space))
+
+ def descr_hex(self, space):
+ return space.hex(self.descr_int(space))
+
def descr_nonzero(self, space):
dtype = self.get_dtype(space)
return space.wrap(dtype.itemtype.bool(self))
@@ -511,6 +517,8 @@
__long__ = interp2app(W_GenericBox.descr_long),
__float__ = interp2app(W_GenericBox.descr_float),
__nonzero__ = interp2app(W_GenericBox.descr_nonzero),
+ __oct__ = interp2app(W_GenericBox.descr_oct),
+ __hex__ = interp2app(W_GenericBox.descr_hex),
__add__ = interp2app(W_GenericBox.descr_add),
__sub__ = interp2app(W_GenericBox.descr_sub),
diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -18,6 +18,15 @@
#raises(TypeError, np.complex_, '1+2j')
assert math.isnan(np.complex_(None))
+ def test_builtin(self):
+ import numpy as np
+ assert oct(np.int32(11)) == '013'
+ assert oct(np.float32(11.6)) == '013'
+ assert oct(np.complex64(11-12j)) == '013'
+ assert hex(np.int32(11)) == '0xb'
+ assert hex(np.float32(11.6)) == '0xb'
+ assert hex(np.complex64(11-12j)) == '0xb'
+
def test_pickle(self):
from numpypy import dtype, zeros
try:
More information about the pypy-commit
mailing list