10000 [Bug]: Pyparsing warnings emitted in mathtext · Issue #25204 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[Bug]: Pyparsing warnings emitted in mathtext #25204
Closed
@jmd-dk

Description

@jmd-dk

Bug summary

When plotting anything with at least one logarithmic axes (plt.semilogx(), plt.semilogy(), plt.loglog()) I get two warnings emitted due to code in _mathtext.py. These warnings are not emitted by default, but appears when running Python with e.g. -Wdefault.

Code for reproduction

import matplotlib.pyplot as plt
plt.semilogx([1, 2], [3, 4])
plt.savefig('plot.png')

Actual outcome

/path/to/python/lib/python3.9/site-packages/matplotlib/_mathtext.py:1871: UserWarning: warn_name_set_on_empty_Forward: setting results name 'sym' on Forward expression that has no contained expression
  - p.placeable("sym"))
/path/to/python/lib/python3.9/site-packages/matplotlib/_mathtext.py:1876: UserWarning: warn_ungrouped_named_tokens_in_collection: setting results name 'name' on ZeroOrMore expression collides with 'name' on contained expression
  "{" + ZeroOrMore(p.simple | p.unknown_symbol)("name") + "}")

Expected outcome

No warnings/text should be printed.

Additional information

To see the warnings from the above code, save it to e.g. test.py and run it as either

python -Wdefault test.py

or

PYTHONWARNINGS=default python test.py

The two warnings are triggered by the following lines within matplotlib/_mathtext.py:

        p.accent <<= (
            csnames("accent", [*self._accent_map, *self._wide_accents])
            - p.placeable("sym")
        p.operatorname <<= cmd(
            r"\operatorname",
            "{" + ZeroOrMore(p.simple | p.unknown_symbol)("name") + "}")

where the various attributes on p are instances of pyparsing.Forward.

The warnings appear with Pyparsing versions 3.0.0–3.0.9 but not prior to 3.0.0 (e.g. 2.4.7). Also, the warnings only appear for Matplotlib versions 3.6.0–3.6.3, not e.g. 3.5.3

Operating system

Linux Mint 20

Matplotlib Version

3.6.3

Matplotlib Backend

QtAgg

Python version

3.8.5

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    < 2A8F ul class="prc-ActionList-ActionList-X4RiC OptionsSection-module__ActionListOverrides--M6klF" data-dividers="false" data-variant="full">
    0