-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
BUG: polynomial string options setting is not context safe #22825
Copy link
Copy link
Closed
Description
While building numpy 1.24.0 for conda-forge, we ran into the following errors. All three errors seem to be related to perhaps overzealously prettifying the serialization of polynomials, so for now we skipped those tests on osx+pypy. Details below.
=================================== FAILURES ===================================
__________________________ TestPrintOptions.test_str ___________________________
[gw2] darwin -- Python 3.8.13 $PREFIX/bin/python
self = <numpy.polynomial.tests.test_printing.TestPrintOptions object at 0x00007f9c0008d600>
def test_str(self):
p = poly.Polynomial([1/2, 1/7, 1/7*10**8, 1/7*10**9])
> assert_equal(str(p), '0.5 + 0.14285714 x + 14285714.28571429 x**2 '
'+ (1.42857143e+08) x**3')
E AssertionError:
E Items are not equal:
E ACTUAL: '0.5 + 0.14285714·x + 14285714.28571429·x² + (1.42857143e+08)·x³'
E DESIRED: '0.5 + 0.14285714 x + 14285714.28571429 x**2 + (1.42857143e+08) x**3'
p = Polynomial([5.00000000e-01, 1.42857143e-01, 1.42857143e+07, 1.42857143e+08], domain=[-1, 1], window=[-1, 1], symbol='x')
self = <numpy.polynomial.tests.test_printing.TestPrintOptions object at 0x00007f9c0008d600>
[...]/lib/pypy3.8/site-packages/numpy/polynomial/tests/test_printing.py:483: AssertionError
_____________________ TestPrintOptions.test_switch_to_exp ______________________
[gw2] darwin -- Python 3.8.13 $PREFIX/bin/python
self = <numpy.polynomial.tests.test_printing.TestPrintOptions object at 0x00007f9c0008d0c0>
def test_switch_to_exp(self):
for i, s in enumerate(SWITCH_TO_EXP):
with printoptions(precision=i):
p = poly.Polynomial([1.23456789*10**-i
for i in range(i//2+3)])
> assert str(p).replace('\n', ' ') == s
E AssertionError: assert '1.0 + (1.0e-... (1.0e-02)·x²' == '1.0 + (1.0e-...1.0e-02) x**2'
E - 1.0 + (1.0e-01) x + (1.0e-02) x**2
E ? ^ ^ ^^^
E + 1.0 + (1.0e-01)·x + (1.0e-02)·x²
E ? ^ ^ ^
i = 0
p = Polynomial([1.23456789, 0.12345679, 0.01234568], domain=[-1, 1], window=[-1, 1], symbol='x')
s = '1.0 + (1.0e-01) x + (1.0e-02) x**2'
self = <numpy.polynomial.tests.test_printing.TestPrintOptions object at 0x00007f9c0008d0c0>
[...]/lib/pypy3.8/site-packages/numpy/polynomial/tests/test_printing.py:517: AssertionError
_______________________ TestPrintOptions.test_non_finite _______________________
[gw2] darwin -- Python 3.8.13 $PREFIX/bin/python
self = <numpy.polynomial.tests.test_printing.TestPrintOptions object at 0x00007f9c0008cf00>
def test_non_finite(self):
p = poly.Polynomial([nan, inf])
> assert str(p) == 'nan + inf x'
E AssertionError: assert 'nan + inf·x' == 'nan + inf x'
E - nan + inf x
E ? ^
E + nan + inf·x
E ? ^
p = Polynomial([nan, inf], domain=[-1, 1], window=[-1, 1], symbol='x')
self = <numpy.polynomial.tests.test_printing.TestPrintOptions object at 0x00007f9c0008cf00>
[...]/lib/pypy3.8/site-packages/numpy/polynomial/tests/test_printing.py:521: AssertionError
@mattip speculated:
Weird. So PyPy is prettifying the polynomial where CPython does not? Perhaps some terminal discovery routine is behaving differently, so PyPy renders a utf-8 terminal and CPython renders ascii?
Reactions are currently unavailable