Skip to content
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
30 changes: 12 additions & 18 deletions plotly/figure_factory/_scatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,36 @@ def endpts_to_intervals(endpts):
"""
length = len(endpts)
# Check if endpts is a list or tuple
if not (isinstance(endpts, (tuple)) or isinstance(endpts, (list))):
if not isinstance(endpts, (list, tuple)):
raise exceptions.PlotlyError(
"The intervals_endpts argument must "
"be a list or tuple of a sequence "
"of increasing numbers."
)
# Check if endpts contains only numbers
for item in endpts:
# Single-pass validation for both string element and increasing check
prev = None
for i, item in enumerate(endpts):
if isinstance(item, str):
raise exceptions.PlotlyError(
"The intervals_endpts argument "
"must be a list or tuple of a "
"sequence of increasing "
"numbers."
)
# Check if numbers in endpts are increasing
for k in range(length - 1):
if endpts[k] >= endpts[k + 1]:
if prev is not None and prev >= item:
raise exceptions.PlotlyError(
"The intervals_endpts argument "
"must be a list or tuple of a "
"sequence of increasing "
"numbers."
)
else:
intervals = []
# add -inf to intervals
intervals.append([float("-inf"), endpts[0]])
for k in range(length - 1):
interval = []
interval.append(endpts[k])
interval.append(endpts[k + 1])
intervals.append(interval)
# add +inf to intervals
intervals.append([endpts[length - 1], float("inf")])
return intervals
prev = item

# Build the intervals efficiently using list comprehensions
intervals = [[float("-inf"), endpts[0]]]
intervals.extend([[endpts[k], endpts[k + 1]] for k in range(length - 1)])
intervals.append([endpts[-1], float("inf")])
return intervals


def hide_tick_labels_from_box_subplots(fig):
Expand Down