Ask Your Question
0

PolynomialRing and from __future__ import unicode_literals

asked 2012-09-29 04:09:05 -0500

updated 2012-09-29 04:11:07 -0500

Hello

sage: from __future__ import unicode_literals
sage: R=PolynomialRing(QQ,'x')

TypeError Traceback (most recent call last)

/home/moky/script/<ipython console=""> in <module>()

/home/moky/Sage/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_ring_constructor.pyc in PolynomialRing(base_ring, arg1, arg2, sparse, order, names, name, implementation) 425 if R is None: 426 raise TypeError("invalid input (%s, %s, %s) to PolynomialRing function; please see the docstring for that function"%( --> 427 base_ring, arg1, arg2)) 428 429 return R

TypeError: invalid input (Rational Field, x, None) to PolynomialRing function; please see the docstring for that function

I guess this is the same kind of problem that the one in this question

By the way, this is "fixed" by using str :

sage: R=PolynomialRing(QQ,str('x'))
sage: f=R.lagrange_polynomial([(0,1),(1,4)]);f
3*x + 1
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2012-09-29 04:52:42 -0500

DSM gravatar image

There are lots of places in the Sage codebase, including PolynomialRing, where someone does an isinstance(something, str) when they should do isinstance(something, basestring), where basestring is the shared parent of str and unicode.

In this case:

elif isinstance(arg1, str) or (isinstance(arg1, (list,tuple)) and len(arg1) == 1):

Because of how the branching works, it looks like you could also get away with making the names a list:

sage: from __future__ import unicode_literals
sage: R = PolynomialRing(QQ, 'x')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Applications/sage/devel/sage-main/sage/<ipython console> in <module>()

/Applications/sage/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_ring_constructor.pyc in PolynomialRing(base_ring, arg1, arg2, sparse, order, names, name, implementation)
    425     if R is None:
    426         raise TypeError("invalid input (%s, %s, %s) to PolynomialRing function; please see the docstring for that function"%(
--> 427             base_ring, arg1, arg2))
    428 
    429     return R

TypeError: invalid input (Rational Field, x, None) to PolynomialRing function; please see the docstring for that function
sage: R = PolynomialRing(QQ, ['x'])
sage:

but this could lead to similar problems elsewhere.

edit flag offensive delete link more

Comments

Are you suggesting you want to grep through those and make a patch? :-)

kcrisman gravatar imagekcrisman ( 2012-09-29 15:04:33 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-09-29 04:09:05 -0500

Seen: 194 times

Last updated: Sep 29 '12