When did this work most recently? Is it possible that the added test is not similar enough to your use case?
It "works" on the latest release version, the error only popped up in ourpip-pre run that usesscientific-python-nightly-wheels : https://github.com/mne-tools/mne-python/actions/runs/5858016804/job/15881180313#step:17:5090 I put "works" in scare quotes because if I revert to matplotlib 3.7 locally and check the type it'snp.ndarray , and it does not raise an error. But if I then force MNE-Python to draw during image creation with aax.figure.canvas.draw_idle() and at the MPL end: - Hack into
matplotlib/image.py and add some print statements to__init__.py :print('\ninitializing')print(type(self))print(kwargs.get('clip_box', None))print(self.get_clip_box())
- Add a
@property forclipbox with @clipbox.setter so I can see who sets it:@clipbox.setterdef clipbox(self, clip_box): import inspect print('\nsetting') print(inspect.stack()[1]) print(clip_box) self._clipbox = clip_box
- Add some print statements to
make_image (plus aRuntimeError to make it quit after the conditional inmake_image ):print('making')print(self.get_clip_box())print(self.axes.bbox)
It looks like that in 3.7 the clip_box we pass never actually gets used, because it gets overwritten byset_clip_path : Print statements$ pytest mne/viz/tests/test_topo.py -xsk test_plot_tfr_topo...mne/viz/tests/test_topo.py settingFrameInfo(frame=<frame at 0x7f652914aae0, file '/home/larsoner/python/virtualenvs/base/lib/python3.11/site-packages/matplotlib/artist.py', line 191, code __init__>, filename='/home/larsoner/python/virtualenvs/base/lib/python3.11/site-packages/matplotlib/artist.py', lineno=191, function='__init__', code_context=[' self.clipbox = None\n'], index=0, positions=Positions(lineno=191, end_lineno=191, col_offset=8, end_col_offset=20))NonesettingFrameInfo(frame=<frame at 0x7f652914aae0, file '/home/larsoner/python/virtualenvs/base/lib/python3.11/site-packages/matplotlib/artist.py', line 774, code set_clip_box>, filename='/home/larsoner/python/virtualenvs/base/lib/python3.11/site-packages/matplotlib/artist.py', lineno=774, function='set_clip_box', code_context=[' self.clipbox = clipbox\n'], index=0, positions=Positions(lineno=774, end_lineno=774, col_offset=8, end_col_offset=20))[0.06488496 0.62804889 0.03376805 0.02814004]initializing<class 'matplotlib.image.AxesImage'>[0.06488496 0.62804889 0.03376805 0.02814004][0.06488496 0.62804889 0.03376805 0.02814004]settingFrameInfo(frame=<frame at 0x7f65297c6a40, file '/home/larsoner/python/virtualenvs/base/lib/python3.11/site-packages/matplotlib/artist.py', line 808, code set_clip_path>, filename='/home/larsoner/python/virtualenvs/base/lib/python3.11/site-packages/matplotlib/artist.py', lineno=808, function='set_clip_path', code_context=[' self.clipbox = TransformedBbox(Bbox.unit(),\n'], index=0, positions=Positions(lineno=808, end_lineno=808, col_offset=16, end_col_offset=28))TransformedBbox( Bbox(x0=0.0, y0=0.0, x1=1.0, y1=1.0), CompositeGenericTransform( CompositeGenericTransform( BboxTransformTo( Bbox(x0=0.0, y0=0.0, x1=1.0, y1=1.0)), Affine2D().scale(1.0)), BboxTransformTo( TransformedBbox( Bbox(x0=0.015, y0=0.025, x1=0.8879999999999999, y1=0.975), BboxTransformTo( TransformedBbox( Bbox(x0=0.0, y0=0.0, x1=6.4, y1=4.8), Affine2D().scale(100.0)))))))makingTransformedBbox( Bbox(x0=0.0, y0=0.0, x1=1.0, y1=1.0), CompositeGenericTransform( CompositeGenericTransform( BboxTransformTo( Bbox(x0=0.0, y0=0.0, x1=1.0, y1=1.0)), Affine2D().scale(1.0)), BboxTransformTo( TransformedBbox( Bbox(x0=0.015, y0=0.025, x1=0.8879999999999999, y1=0.975), BboxTransformTo( TransformedBbox( Bbox(x0=0.0, y0=0.0, x1=6.4, y1=4.8), Affine2D().scale(100.0)))))))TransformedBbox( Bbox(x0=0.015, y0=0.025, x1=0.8879999999999999, y1=0.975), BboxTransformTo( TransformedBbox( Bbox(x0=0.0, y0=0.0, x1=6.4, y1=4.8), Affine2D().scale(100.0))))F...mne/viz/topo.py:508: in _imshow_tfr_unified ax.figure.canvas.draw_idle()../virtualenvs/base/lib/python3.11/site-packages/matplotlib/backend_bases.py:2082: in draw_idle self.draw(*args, **kwargs)...../virtualenvs/base/lib/python3.11/site-packages/matplotlib/image.py:641: in draw im, l, b, trans = self.make_image(../virtualenvs/base/lib/python3.11/site-packages/matplotlib/image.py:968: in make_image raise RuntimeErrorE RuntimeError
So in other words,ndarray was never actually used / checked. So this makes me think this could be closed... But a follow-up question arises: passingtuple(my_ndarray_clip_box) also does not error, even onmain . It seems like it should, but maybe somewhere in there it casts thetuple , but at least looking at the 3.7 code it doesn't look like it. Making the same changes onmain and passingclip_box=tuple(my_ndarray) I get: Using tuple on mainmne/viz/tests/test_topo.py settingFrameInfo(frame=<frame at 0x7fc02cf24f60, file '/home/larsoner/python/matplotlib/lib/matplotlib/artist.py', line 191, code __init__>, filename='/home/larsoner/python/matplotlib/lib/matplotlib/artist.py', lineno=191, function='__init__', code_context=[' self.clipbox = None\n'], index=0, positions=Positions(lineno=191, end_lineno=191, col_offset=8, end_col_offset=20))NonesettingFrameInfo(frame=<frame at 0x7fc02cf24f60, file '/home/larsoner/python/matplotlib/lib/matplotlib/artist.py', line 767, code set_clip_box>, filename='/home/larsoner/python/matplotlib/lib/matplotlib/artist.py', lineno=767, function='set_clip_box', code_context=[' self.clipbox = clipbox\n'], index=0, positions=Positions(lineno=767, end_lineno=767, col_offset=12, end_col_offset=24))(np.float64(0.06488496453324114), np.float64(0.6280488934398878), np.float64(0.03376805371721399), np.float64(0.028140044764344993))initializing<class 'matplotlib.image.AxesImage'>(np.float64(0.06488496453324114), np.float64(0.6280488934398878), np.float64(0.03376805371721399), np.float64(0.028140044764344993))(np.float64(0.06488496453324114), np.float64(0.6280488934398878), np.float64(0.03376805371721399), np.float64(0.028140044764344993))settingFrameInfo(frame=<frame at 0x7fc02d5d7440, file '/home/larsoner/python/matplotlib/lib/matplotlib/artist.py', line 801, code set_clip_path>, filename='/home/larsoner/python/matplotlib/lib/matplotlib/artist.py', lineno=801, function='set_clip_path', code_context=[' self.clipbox = TransformedBbox(Bbox.unit(),\n'], index=0, positions=Positions(lineno=801, end_lineno=801, col_offset=16, end_col_offset=28))TransformedBbox( Bbox(x0=0.0, y0=0.0, x1=1.0, y1=1.0), CompositeGenericTransform( CompositeGenericTransform( BboxTransformTo( Bbox(x0=0.0, y0=0.0, x1=1.0, y1=1.0)), Affine2D().scale(1.0)), BboxTransformTo( TransformedBbox( Bbox(x0=0.015, y0=0.025, x1=0.8879999999999999, y1=0.975), BboxTransformTo( TransformedBbox( Bbox(x0=0.0, y0=0.0, x1=6.4, y1=4.8), Affine2D().scale(100.0)))))))makingTransformedBbox( Bbox(x0=0.0, y0=0.0, x1=1.0, y1=1.0), CompositeGenericTransform( CompositeGenericTransform( BboxTransformTo( Bbox(x0=0.0, y0=0.0, x1=1.0, y1=1.0)), Affine2D().scale(1.0)), BboxTransformTo( TransformedBbox( Bbox(x0=0.015, y0=0.025, x1=0.8879999999999999, y1=0.975), BboxTransformTo( TransformedBbox( Bbox(x0=0.0, y0=0.0, x1=6.4, y1=4.8), Affine2D().scale(100.0)))))))TransformedBbox( Bbox(x0=0.015, y0=0.025, x1=0.8879999999999999, y1=0.975), BboxTransformTo( TransformedBbox( Bbox(x0=0.0, y0=0.0, x1=6.4, y1=4.8), Affine2D().scale(100.0))))
No idea if this is doing the right thing or not (my head is spinning trying to interpret the flow)... But it seems like you should get a TypeError that theclip_box is not the correct type at the very least in thendarray case, maybe also thetuple case. So maybe that's the right approach here rather than reverting#26326 ? |
This is a bug-report-as-PR -- MNE-Python
main
just started failing with:So passing
bbox-like
used to work but now doesn't (i.e., the test added here should fail). cc@oscargus as this seems to have been introduced by#26326Not sure if the correct solution here is to cast to
BboxBase
if not an instance of one or something... but at least in MNE-Python we can work around for now by passingtuple(bbox)
or so, so no rush from our end. 🤷