#16378: list_plot throws a TypeError with complex lists
--------------------------------------+------------------------
Reporter: bradlys | Owner: bradlys
Type: defect | Status: new
Priority: major | Milestone: sage-6.3
Component: packages: standard | Resolution:
Keywords: | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
Dependencies: | Stopgaps:
--------------------------------------+------------------------
Comment (by bradlys):
I think what's happening is that at line 1792, a TypeError is thrown.
{{{
try:
from sage.rings.all import RDF #1791
tmp = RDF(data[0]) #1792
data = list(enumerate(data)) #1793
except TypeError:
pass
try:
if plotjoined:
return line(data, **kwargs)
else:
return point(data, **kwargs)
except (TypeError, IndexError):
# Assume we have complex-valued input and plot real and imaginary
parts.
# Need to catch IndexError because if data is, say, [(0, 1), (1, I)],
# point3d() throws an IndexError on the (0,1) before it ever
# gets to (1, I).
from sage.rings.complex_field import ComplexField
CC = ComplexField()
# if we get here, we already did "list(enumerate(data))",
# so look at z[1] in inner list
data = [(z.real(), z.imag()) for z in [CC(z[1]) for z in data]] # LINE
1810
if plotjoined:
return line(data, **kwargs)
else:
return point(data, **kwargs)
}}}
I tested this theory by running this code in a sage worksheet on SMC:
{{{
from sage.rings.all import RDF
data = [1+i,4+i,4+2*i,2+2*i,2+3*i,1+3*i,1+i]
tmp = RDF(data[0])
}}}
Which throws a TypeError saying "TypeError: Unable to convert 1.0 + 1.0*I
to float; use abs() or real_part() as desired".
That makes sense but that ends up skipping line 1793 where we need data =
list(enumerate(data)) to occur. I could add data = list(enumerate(data))
at line 1809 and I think that would solve the issue since that's the case
where you have complex-valued input.
I tried this snippet, again in SMC, which does produce the desired output
as far as I can tell.
{{{
from sage.rings.all import RDF
data = [1+i,4+i,4+2*i,2+2*i,2+3*i,1+3*i,1+i]
data = list(enumerate(data))
from sage.rings.complex_field import ComplexField
CC = ComplexField()
data = [(z.real(), z.imag()) for z in [CC(z[1]) for z in data]]
point(data)
}}}
--
Ticket URL: <http://trac.sagemath.org/ticket/16378#comment:5>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.