8000 Some `matplotlib` mathtext yields a `ParseFatalException` · Issue #318 · pyparsing/pyparsing · GitHub
[go: up one dir, main page]

Skip to content

Some matplotlib mathtext yields a ParseFatalException #318

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

Closed
heltluke opened this issue Oct 25, 2021 · 7 comments
Closed

Some matplotlib mathtext yields a ParseFatalException #318

heltluke opened this issue Oct 25, 2021 · 7 comments

Comments

@heltluke
Copy link

Minimal example

import matplotlib.pyplot as plt

plt.plot(range(5), '.')
plt.title(r"$x \cdot y$")
plt.show()

presently fails with ParseFatalException: Unknown symbol: \cdot, found '\' (at char 2), (line:1, col:3).

Looking at the matplotlib docs, this seems to be somehow related to their use of pyparsing https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/_mathtext.py#L15.

@ptmcg
Copy link
Member
ptmcg commented Oct 25, 2021

This is a change from 2.4.7.

ParseFatalExceptions were changed to actually be immediately fatal, rather than checking another alternative to see if it might be a match. In the case of this expression, "\cdot" is parsed as a p.single_symbol | p.symbol_name. It fails to match a p.single_symbol, but would match a p.symbol_name. When single_symbol fails, it raises a ParseFatalException, not an ordinary exception - most likely so that the reported error location is closer to the actual error.

This behavior (where ParseFatalException was not immediately reraised) has been this way for a long time, but was raised as an issue this past summer. I think the current behavior is the correct behavior for a ParseFatalException, but perhaps could be modified if mathtext raises a ParseSyntaxException (this would still require code change in pyparsing). I may just push out a 3.0.2 with this particular fix reverted, with a longer-term plan to get this working correctly.

@anntzer
Copy link
anntzer commented Oct 26, 2021

Note that this was already fixed (empirically...) in mpl master by https://github.com/matplotlib/matplotlib/pull/21454/files. I'm not really sure I understand your explanation, though, as we fixed that on symbol_name, rather than on single_symbol?

@ptmcg
Copy link
Member
ptmcg commented Nov 13, 2021

Is this resolved now?

@anntzer
Copy link
anntzer commented Nov 14, 2021

We are trying to decide on the right fix on Matplotlib's side, perhaps you can comment on matplotlib/matplotlib#21606?

@ptmcg
Copy link
Member
ptmcg commented Jul 11, 2022

Any further requirements on pyparsing here (other than "please stop breaking our stuff by making internal changes in pyparsing")?

@anntzer
Copy link
anntzer commented Jul 11, 2022

I think everything is good on Matplotlib's side now.

@ptmcg
Copy link
Member
ptmcg commented Jul 11, 2022

Thanks, closing

@ptmcg ptmcg closed this as completed Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0