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

Fixed issue in list_plot where it assumed data had been enumerated when it might not have been #39481

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
29 changes: 26 additions & 3 deletions src/sage/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3107,6 +3107,24 @@
100.0
sage: d['ymin']
100.0

Verify that :issue:`38037` is fixed::

sage: list_plot([(0,-1),(1,-2),(2,-3),(3,-4),(4,None)])
Traceback (most recent call last):
...
TypeError: unable to coerce to a ComplexNumber:
<class 'sage.rings.integer.Integer'>

Test the codepath where ``list_enumerated`` is ``False``::

sage: list_plot([3+I, 4, I, 1+5*i, None, 1+i])
Graphics object consisting of 1 graphics primitive

Test the codepath where ``list_enumerated`` is ``True``::

sage: list_plot([4, 3+I, I, 1+5*i, None, 1+i])
Graphics object consisting of 1 graphics primitive
"""
from sage.plot.all import point
try:
Expand All @@ -3124,10 +3142,12 @@
else:
list_data = list(data.items())
return list_plot(list_data, plotjoined=plotjoined, **kwargs)
list_enumerated = False
try:
from sage.rings.real_double import RDF
RDF(data[0])
data = list(enumerate(data))
list_enumerated = True
except TypeError: # we can get this TypeError if the element is a list
# or tuple or numpy array, or an element of CC, CDF
# We also want to avoid doing CC(data[0]) here since it will go
Expand All @@ -3138,6 +3158,7 @@
# element of the Symbolic Ring.
if isinstance(data[0], Expression):
data = list(enumerate(data))
list_enumerated = True

Check warning on line 3161 in src/sage/plot/plot.py

View check run for this annotation

Codecov / codecov/patch

src/sage/plot/plot.py#L3161

Added line #L3161 was not covered by tests

try:
if plotjoined:
Expand All @@ -3150,9 +3171,11 @@
# point3d() throws an IndexError on the (0,1) before it ever
# gets to (1, I).
from sage.rings.cc import CC
# 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]]
# It is not guaranteed that we enumerated the data so we have two cases
if list_enumerated:
data = [(z.real(), z.imag()) for z in [CC(z[1]) for z in data]]
else:
data = [(z.real(), z.imag()) for z in [CC(z) for z in data]]
if plotjoined:
return line(data, **kwargs)
else:
Expand Down
Loading