Skip to content

Commit 349bc2d

Browse files
author
Noel Roemmele
committed
Fixed issue in list_plot where it assumed data had been enumerated when it might not have been
1 parent dc99dc8 commit 349bc2d

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/sage/plot/plot.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,6 +3107,22 @@ def list_plot(data, plotjoined=False, **kwargs):
31073107
100.0
31083108
sage: d['ymin']
31093109
100.0
3110+
3111+
Verify that :trac:`38037` is fixed::
3112+
3113+
sage: list_plot([(0,-1),(1,-2),(2,-3),(3,-4),(4,None)])
3114+
Traceback (most recent call last):
3115+
...
3116+
TypeError: unable to coerce to a ComplexNumber:
3117+
<class 'sage.rings.integer.Integer'>
3118+
3119+
#Non enumerated list example
3120+
sage: list_plot([3+I, 4, I, 1+5*i, None, 1+i])
3121+
Graphics object consisting of 1 graphics primitive
3122+
3123+
#Enumerated list example
3124+
sage: list_plot([4, 3+I, I, 1+5*i, None, 1+i])
3125+
Graphics object consisting of 1 graphics primitive
31103126
"""
31113127
from sage.plot.all import point
31123128
try:
@@ -3124,10 +3140,12 @@ def list_plot(data, plotjoined=False, **kwargs):
31243140
else:
31253141
list_data = list(data.items())
31263142
return list_plot(list_data, plotjoined=plotjoined, **kwargs)
3143+
listEnumerated = False
31273144
try:
31283145
from sage.rings.real_double import RDF
31293146
RDF(data[0])
31303147
data = list(enumerate(data))
3148+
listEnumerated = True
31313149
except TypeError: # we can get this TypeError if the element is a list
31323150
# or tuple or numpy array, or an element of CC, CDF
31333151
# We also want to avoid doing CC(data[0]) here since it will go
@@ -3138,6 +3156,7 @@ def list_plot(data, plotjoined=False, **kwargs):
31383156
# element of the Symbolic Ring.
31393157
if isinstance(data[0], Expression):
31403158
data = list(enumerate(data))
3159+
listEnumerated = True
31413160

31423161
try:
31433162
if plotjoined:
@@ -3150,9 +3169,11 @@ def list_plot(data, plotjoined=False, **kwargs):
31503169
# point3d() throws an IndexError on the (0,1) before it ever
31513170
# gets to (1, I).
31523171
from sage.rings.cc import CC
3153-
# if we get here, we already did "list(enumerate(data))",
3154-
# so look at z[1] in inner list
3155-
data = [(z.real(), z.imag()) for z in [CC(z[1]) for z in data]]
3172+
# It is not guaranteed that we enumerated the data so we have two cases
3173+
if listEnumerated:
3174+
data = [(z.real(), z.imag()) for z in [CC(z[1]) for z in data]]
3175+
else:
3176+
data = [(z.real(), z.imag()) for z in [CC(z) for z in data]]
31563177
if plotjoined:
31573178
return line(data, **kwargs)
31583179
else:

0 commit comments

Comments
 (0)