From ab6b6f4ee8ad5b009542c650bfcda69cb3f932f9 Mon Sep 17 00:00:00 2001 From: Colin Ophus Date: Sat, 1 Aug 2026 11:18:53 -0500 Subject: [PATCH] Require matplotlib >= 3.11 on python >= 3.11 to fix pyparsing warnings The 'parseString' / 'parseAll' / 'resetCache' deprecation messages that flood plotting output (e.g. during strainmap.get_strain) come from matplotlib's mathtext, not py4DSTEM: matplotlib < 3.11 calls pyparsing's deprecated camelCase API once per rendered label, and pyparsing >= 3.3 displays those warnings by default. matplotlib 3.11 switched to the snake_case API, fixing the arguments at the source. Require matplotlib >= 3.11 where python allows it (3.11 needs python 3.11+; older pythons keep the previous floor), and drop the warnings filter added earlier - notebook environments manipulate warning filters per cell, so filtering was unreliable, and upgrading matplotlib removes the deprecated calls instead of hiding them. Co-Authored-By: Claude Fable 5 --- py4DSTEM/__init__.py | 15 --------------- setup.py | 6 +++++- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/py4DSTEM/__init__.py b/py4DSTEM/__init__.py index 247c6babc..e26f24c78 100644 --- a/py4DSTEM/__init__.py +++ b/py4DSTEM/__init__.py @@ -1,21 +1,6 @@ from py4DSTEM.version import __version__ from emdfile import tqdmnd -# pyparsing >= 3.3 raises PyparsingDeprecationWarning -- a UserWarning -# subclass, so it is displayed by default -- whenever a dependency such as -# older matplotlib mathtext calls its camelCase compatibility API. This fires -# once per rendered label and floods plotting output with messages like -# "'parseString' deprecated - use 'parse_string'". There is nothing a py4DSTEM -# user can do about it, so silence that category here. -import warnings as _warnings - -try: - from pyparsing import PyparsingDeprecationWarning as _PyparsingDeprecationWarning - - _warnings.filterwarnings("ignore", category=_PyparsingDeprecationWarning) -except ImportError: - pass - from importlib.metadata import packages_distributions is_package_lite = "py4DSTEM-lite" in packages_distributions()["py4DSTEM"] diff --git a/setup.py b/setup.py index a220b9cf5..242f332f2 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,11 @@ "h5py >= 3.2.0", "hdf5plugin >= 4.1.3", "ncempy >= 1.8.1", - "matplotlib >= 3.2.2", + # matplotlib < 3.11 calls pyparsing's deprecated camelCase API from + # mathtext, which floods plotting output with deprecation warnings + # under pyparsing >= 3.3; require 3.11 wherever python allows it + "matplotlib >= 3.2.2; python_version < '3.11'", + "matplotlib >= 3.11; python_version >= '3.11'", "scikit-image >= 0.17.2", "scikit-learn >= 0.23.2", "scikit-optimize >= 0.9.0",