Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Under matplotlib 3.0.0rc1, the return value of matplotlib.get_backend() is a sentinel object:
In [2]: matplotlib.get_backend()Out[2]: <object at 0x111292d50>In [3]: backend = matplotlib.get_backend()In [4]: backend.lower()---------------------------------------------------------------------------AttributeError Traceback (most recent call last)<ipython-input-4-f3c7164fcd07> in <module>()----> 1 backend.lower()AttributeError: 'object' object has no attribute 'lower'
Under matplotlib 2.2.3 I get:
In [1]: import matplotlibIn [2]: matplotlib.get_backend()Out[2]: 'MacOSX'In [3]: backend = matplotlib.get_backend()In [4]: backend.lower()Out[4]: 'macosx'
For backward compatibility purposes it would be really nice if matplotlib 3.0.0 could return an object that at least acted like a string. In particular right now I'd like it to have alower()
method. I'd also like it if it had a nice__repr__
or__str__
implementation instead of printing out as an opaque object of typeobject
.
The former is for backward compatibility, as the change breaks some of the yt plotting code --- in particular here's a failure from the test suite:
======================================================================ERROR: Failure: AttributeError ('object' object has no attribute 'lower')----------------------------------------------------------------------Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/nose/failure.py", line 39, in runTest raise self.exc_val.with_traceback(self.tb) File "/usr/local/lib/python3.7/site-packages/nose/loader.py", line 418, in loadTestsFromName addr.filename, addr.module) File "/usr/local/lib/python3.7/site-packages/nose/importer.py", line 47, in importFromPath return self.importFromDir(dir_path, fqname) File "/usr/local/lib/python3.7/site-packages/nose/importer.py", line 94, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imp.py", line 235, in load_module return load_source(name, filename, file) File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imp.py", line 172, in load_source module = _load(spec) File "<frozen importlib._bootstrap>", line 696, in _load File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Users/goldbaum/Documents/yt-git-fixes/yt/visualization/tests/test_color_maps.py", line 23, in <module> class TestColorMaps(unittest.TestCase): File "/Users/goldbaum/Documents/yt-git-fixes/yt/visualization/tests/test_color_maps.py", line 34, in TestColorMaps @requires_backend('Agg') File "/Users/goldbaum/Documents/yt-git-fixes/yt/testing.py", line 1143, in requires_backend if backend.lower() == matplotlib.get_backend().lower():AttributeError: 'object' object has no attribute 'lower'
This is code that's internal to yt's test suite, but I wouldn't be at all surprised if there's other code out there that assumesmatplotlib.get_backend()
returns a string. For example:
https://github.com/search?q=matplotlib+get_backend+lower&type=Code