Skip to content

BLD: pin matplotlib to < 3.11.0#37

Merged
tylerjereddy merged 2 commits into
mainfrom
awitmer_pin_matplotlib
Jun 16, 2026
Merged

BLD: pin matplotlib to < 3.11.0#37
tylerjereddy merged 2 commits into
mainfrom
awitmer_pin_matplotlib

Conversation

@adamwitmer

@adamwitmer adamwitmer commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

As mentioned in issue #36, the newest release of matplotlib (3.11.0) includes changes to text and font handling that break tests that rely on pixel level image comparisons (https://matplotlib.org/stable/release/prev_whats_new/whats_new_3.11.0#fonts-and-text). This PR pins matplotlib to versions below 3.11.0 to avoid implementing suggested work-arounds from the matplotlib release notes including:

  1. Regenerating all test images and removing support for versions lower than 3.11.0. I don't think we want to exclude all older versions of matplotlib in our workflow.
  2. Removing text from plots or using placeholders. We specifically check font style with image comparison.
  3. Loosening image comparison tolerances. We are concerned with pixel level changes that may be missed by loosening tolerances, and we have already loosened tolerances to account for sub-pixel level inconsistencies between testing platforms.
  4. Changing the image comparison algorithm used for testing. "Perpetual hashing" was mentioned as one such option, but would require substantial refactoring of the current testing architecture.

AI Disclosure: No AI tools were used in generating original commit to this PR. Claude was used to check what was common practice for implementing dependency version checks in open source packages, and suggestions were cross-referenced with widely used open source packages such as pandas

@adamwitmer adamwitmer changed the title BLD, MAINT: pin matplotlib to < 3.11.0 BLD: pin matplotlib to < 3.11.0 Jun 16, 2026
@adamwitmer adamwitmer force-pushed the awitmer_pin_matplotlib branch from a6d68b5 to 82e169e Compare June 16, 2026 16:45
@tylerjereddy

tylerjereddy commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

If you want to do this temporarily that's fine, but:

  • I'd still expect you to support >= 3.11.0 by the original deadline Mihee asked for; you may need to just check how much more disk space is needed to support reference images for both versions in tests.
  • You should probably error out at import time if the user is using >= 3.11.0, so that you fail "fast and early" until 3.11.x series support is verified/tested.

@tylerjereddy

Copy link
Copy Markdown
Collaborator

In addition to that change, please always include an AI disclosure in your original comment, as noted previously.

* raise ImportError for unsupported matplotlib versions
* add `packaging` dependency to pyproject
@adamwitmer

Copy link
Copy Markdown
Collaborator Author

I added a check to neat_ml/__init__.py to raise an ImportError when importing unsupported versions of matplotlib. I asked an LLM what the best practice was for erroring out at runtime when an unsupported version of a dependency is being used and it suggested using the packaging.version.Version package. pandas does something similar, but with a vendored version of Version (https://github.com/pandas-dev/pandas/blob/main/pandas/util/version/__init__.py) that they use to check some version compatibility, e.g. https://github.com/pandas-dev/pandas/blob/main/pandas/compat/numpy/__init__.py

Locally, this error does raise when importing matplotlib==3.11.0, i.e.:

______________________________________________________________________________________________________________________________ ERROR collecting neat_ml/tests ______________________________________________________________________________________________________________________________
/Users/awitmer/anaconda3/envs/neat_ml_3_12/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
<frozen importlib._bootstrap>:1381: in _gcd_import
    ???
<frozen importlib._bootstrap>:1354: in _find_and_load
    ???
<frozen importlib._bootstrap>:1304: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:488: in _call_with_frames_removed
    ???
<frozen importlib._bootstrap>:1381: in _gcd_import
    ???
<frozen importlib._bootstrap>:1354: in _find_and_load
    ???
<frozen importlib._bootstrap>:1304: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:488: in _call_with_frames_removed
    ???
<frozen importlib._bootstrap>:1381: in _gcd_import
    ???
<frozen importlib._bootstrap>:1354: in _find_and_load
    ???
<frozen importlib._bootstrap>:1325: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:929: in _load_unlocked
    ???
<frozen importlib._bootstrap_external>:994: in exec_module
    ???
<frozen importlib._bootstrap>:488: in _call_with_frames_removed
    ???
neat_ml/__init__.py:6: in <module>
    raise ImportError("Workflow currently only supports `matplotlib<3.11.0`")
E   ImportError: Workflow currently only supports `matplotlib<3.11.0`

However, currently this check is not covered by our tests, is it common practice to add an explicit test for these checks to the repos test suite?

@tylerjereddy

Copy link
Copy Markdown
Collaborator

is it common practice to add an explicit test for these checks to the repos test suite?

No

pandas does something similar, but with a vendored version of Version

Right, because with millions of users adding a new dependency for something so simple as a version check is undesirable, but doesn't matter for us.

@tylerjereddy

Copy link
Copy Markdown
Collaborator

ok, this looks good to go to me, thanks

@tylerjereddy tylerjereddy merged commit d0f64e7 into main Jun 16, 2026
8 checks passed
@tylerjereddy tylerjereddy deleted the awitmer_pin_matplotlib branch June 16, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants