Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Add tests for Polynomial with fractions.Fraction coefficients #24571

Merged
merged 3 commits into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions numpy/polynomial/tests/test_polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

"""
from functools import reduce

from fractions import Fraction
import numpy as np
import numpy.polynomial.polynomial as poly
import pickle
from copy import deepcopy
from numpy.testing import (
assert_almost_equal, assert_raises, assert_equal, assert_,
assert_warns, assert_array_equal, assert_raises_regex)
assert_array_equal, assert_raises_regex)


def trim(x):
Expand Down Expand Up @@ -122,6 +122,25 @@ def test_polypow(self):
res = poly.polypow(c, j)
assert_equal(trim(res), trim(tgt), err_msg=msg)

class TestFraction:

def test_Fraction(self):
# assert we can use Polynomials with coefficients of object dtype
f = Fraction(2, 3)
one = Fraction(1, 1)
zero = Fraction(0, 1)
p = poly.Polynomial([f, f], domain=[zero, one], window=[zero, one])

x = 2 * p + p ** 2
assert_equal(x.coef, np.array([Fraction(16, 9), Fraction(20, 9),
Fraction(4, 9)], dtype=object))
assert_equal(p.domain, [zero, one])
assert_equal(p.coef.dtype, np.dtypes.ObjectDType())
assert_(isinstance(p(f), Fraction))
assert_equal(p(f), Fraction(10, 9))
p_deriv = poly.Polynomial([Fraction(2, 3)], domain=[zero, one],
window=[zero, one])
assert_equal(p.deriv(), p_deriv)

class TestEvaluation:
# coefficients of 1 + 2*x + 3*x**2
Expand Down
Loading