Skip to content

Commit

Permalink
Lint found in ListPlot-point checking branch (#1246)
Browse files Browse the repository at this point in the history
The good stuff from #1245, but alas the thing we were trying to do there can cause an infinite loop in the eval_ListPlot routine. So let's do this part and narrow that PR.
  • Loading branch information
rocky authored Dec 29, 2024
1 parent 2aecdb3 commit 2a27d46
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ jobs:
cd mathics/packages/Combinatorica-repo
# If Combinatorica repo changes, we may need the below altered
# with a branch name, (not HEAD) for testing.
# git pull origin HEAD
git pull origin HEAD
pip install -e .[dev]
remake -x check
9 changes: 7 additions & 2 deletions mathics/core/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1417,8 +1417,13 @@ def rules():
if not isinstance(result, EvalMixin):
return result, False
if result.sameQ(new):
new._timestamp_cache(evaluation)
return new, False
# Even though result and new may be the same,
# new can be a Expression[SymbolConstant: System`List...]
# while "result' might be ListExpression!?
# So make sure to use "result", not "new".
if isinstance(result, Expression):
result._timestamp_cache(evaluation)
return result, False
else:
return result, True

Expand Down
13 changes: 7 additions & 6 deletions mathics/eval/drawing/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,20 @@ def eval_ListPlot(
[xx for xx, yy in plot_groups], [xx for xx, yy in plot_groups], x_range
)
plot_groups = [plot_groups]
elif all(isinstance(line, list) for line in plot_groups):
if not all(isinstance(line, list) for line in plot_groups):
elif all(isinstance(line, (list, tuple)) for line in plot_groups):
if not all(isinstance(line, (list, tuple)) for line in plot_groups):
return

# He have a list of plot groups
if all(
isinstance(point, list) and len(point) == 2
for plot_group in plot_groups
isinstance(point, (list, tuple)) and len(point) == 2
for point in plot_groups
):
pass
elif not is_discrete_plot and all(
not isinstance(point, list) for line in plot_groups for point in line
not isinstance(point, (list, tuple))
for line in plot_groups
for point in line
):
# FIXME: is this right?
y_min = min(plot_groups)[0]
Expand All @@ -229,7 +230,7 @@ def eval_ListPlot(
# Split into plot segments
plot_groups = [[plot_group] for plot_group in plot_groups]
if isinstance(x_range, (list, tuple)):
x_min, m_max = x_range
x_min, x_max = x_range
y_min, y_max = y_range

for lidx, plot_group in enumerate(plot_groups):
Expand Down
2 changes: 1 addition & 1 deletion test/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def evaluate(str_expr: str):
def check_evaluation(
str_expr: Optional[str],
str_expected: Optional[str] = None,
failure_message: str = "",
failure_message: Optional[str] = "",
hold_expected: bool = False,
to_string_expr: Optional[bool] = True,
to_string_expected: bool = True,
Expand Down

0 comments on commit 2a27d46

Please sign in to comment.