Context
We are currently analyzing historical GitHub issues to identify potential compatibility regressions in open-source projects. During this process, we noticed a usage pattern in MockingBird that corresponds to a known unstable API in matplotlib (matplotlib.cm.get_cmap).
Findings
The deprecated cm.get_cmap API is used in models/encoder/inference.py:
# models/encoder/inference.py
cmap = cm.get_cmap() # <--- This line triggers AttributeError on specific versions
mappable = ax.imshow(embed, cmap=cmap)
Evidence & History
This API has a history of instability. It was briefly removed in Matplotlib in 3.9.0, before being restored in patch releases due to community feedback.
The rationale and future removal plan are explicitly documented in the Matplotlib 3.10.0 source code:
# This is an exact copy of pyplot.get_cmap(). It was removed in 3.9, but apparently
# caused more user trouble than expected. Re-added for 3.9.1 and extended the
# deprecation period for two additional minor releases.
@_api.deprecated(
'3.7',
removal='3.11',
alternative="``matplotlib.colormaps[name]`` or ``matplotlib.colormaps.get_cmap()``"
" or ``pyplot.get_cmap()``"
)
def get_cmap(name=None, lut=None):
# ...
Potential Impact
- Suspected Crashes: Users whose environments happen to have
matplotlib==3.9.0 installed likely face immediate AttributeError: module 'matplotlib.cm' has no attribute 'get_cmap' crashes.
- Future Incompatibility: As noted in the source code above, the API is scheduled for permanent removal in version 3.11.
Experimental Evidence
Our local testing confirms that matplotlib.cm.get_cmap was physically removed in Matplotlib 3.9.0, leading to an immediate crash.
Verification on Matplotlib 3.9.0:
>>> import matplotlib
>>> print(matplotlib.__version__)
3.9.0
>>> from matplotlib import cm
>>> cmap = cm.get_cmap(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'matplotlib.cm' has no attribute 'get_cmap'
Suggestions
Option 1: Update API
Consider updating the code to use one of the official alternatives suggested in the Matplotlib source code:
matplotlib.colormaps[name]
matplotlib.colormaps.get_cmap()
pyplot.get_cmap()
Option 2: Restrict Dependency Version
If a code update is not immediate, you might consider temporarily restricting the dependency versions to avoid the unstable releases:
dependencies = [
"matplotlib!=3.9.0,<3.11",
]
Context
We are currently analyzing historical GitHub issues to identify potential compatibility regressions in open-source projects. During this process, we noticed a usage pattern in
MockingBirdthat corresponds to a known unstable API inmatplotlib(matplotlib.cm.get_cmap).Findings
The deprecated
cm.get_cmapAPI is used inmodels/encoder/inference.py:Evidence & History
This API has a history of instability. It was briefly removed in Matplotlib in 3.9.0, before being restored in patch releases due to community feedback.
The rationale and future removal plan are explicitly documented in the Matplotlib 3.10.0 source code:
Potential Impact
matplotlib==3.9.0installed likely face immediateAttributeError: module 'matplotlib.cm' has no attribute 'get_cmap'crashes.Experimental Evidence
Our local testing confirms that
matplotlib.cm.get_cmapwas physically removed in Matplotlib 3.9.0, leading to an immediate crash.Verification on Matplotlib 3.9.0:
Suggestions
Option 1: Update API
Consider updating the code to use one of the official alternatives suggested in the Matplotlib source code:
matplotlib.colormaps[name]matplotlib.colormaps.get_cmap()pyplot.get_cmap()Option 2: Restrict Dependency Version
If a code update is not immediate, you might consider temporarily restricting the dependency versions to avoid the unstable releases: