Author: Brian Kearns <[email protected]>
Branch:
Changeset: r67834:c3b67fad2bc1
Date: 2013-11-04 14:37 -0500
http://bitbucket.org/pypy/pypy/changeset/c3b67fad2bc1/
Log: fix str_format of complex nan/inf
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
@@ -70,3 +70,9 @@
x = tp(1+2j)
assert hasattr(x, '__complex__') == (tp != np.cdouble)
assert complex(x) == 1+2j
+
+ def test_complex_str_format(self):
+ import numpy as np
+ assert str(np.complex128(complex(1, float('nan')))) == '(1+nan*j)'
+ assert str(np.complex128(complex(1, float('inf')))) == '(1+inf*j)'
+ assert str(np.complex128(complex(1, float('-inf')))) == '(1-inf*j)'
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1027,14 +1027,17 @@
def str_format(self, box):
real, imag = self.for_computation(self.unbox(box))
- imag_str = str_format(imag) + 'j'
+ imag_str = str_format(imag)
+ if rfloat.isnan(imag) or rfloat.isinf(imag):
+ imag_str += '*'
+ imag_str += 'j'
# (0+2j) => 2j
if real == 0:
return imag_str
real_str = str_format(real)
- op = '+' if imag >= 0 else ''
+ op = '+' if rfloat.copysign(1, imag) > 0 else ''
return ''.join(['(', real_str, op, imag_str, ')'])
def fill(self, storage, width, box, start, stop, offset):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit