File tree 3 files changed +27
-12
lines changed
doc/api/next_api_changes/deprecations 3 files changed +27
-12
lines changed Original file line number Diff line number Diff line change
1
+ Passing non-int or sequence of non-int to ``Table.auto_set_column_width ``
2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3
+
4
+ Column numbers are ints, and formerly passing any other type was effectively
5
+ ignored. This will become an error in the future.
Original file line number Diff line number Diff line change 24
24
Thanks to John Gill for providing the class and table.
25
25
"""
26
26
27
+ import numpy as np
28
+
27
29
from . import _api , _docstring
28
30
from .artist import Artist , allow_rasterization
29
31
from .patches import Rectangle
@@ -494,14 +496,15 @@ def auto_set_column_width(self, col):
494
496
col : int or sequence of ints
495
497
The indices of the columns to auto-scale.
496
498
"""
497
- # check for col possibility on iteration
498
- try :
499
- iter (col )
500
- except (TypeError , AttributeError ):
501
- self ._autoColumns .append (col )
502
- else :
503
- for cell in col :
504
- self ._autoColumns .append (cell )
499
+ col1d = np .atleast_1d (col )
500
+ if not np .issubdtype (col1d .dtype , np .integer ):
501
+ _api .warn_deprecated ("3.8" , name = "col" ,
502
+ message = "%(name)r must be an int or sequence of ints. "
503
+ "Passing other types is deprecated since %(since)s "
504
+ "and will be removed %(removal)s." )
505
+ return
506
+ for cell in col1d :
507
+ self ._autoColumns .append (cell )
505
508
506
509
self .stale = True
507
510
Original file line number Diff line number Diff line change 1
- import matplotlib .pyplot as plt
2
1
import numpy as np
3
- from matplotlib . testing . decorators import image_comparison , check_figures_equal
2
+ import pytest
4
3
5
- from matplotlib .table import CustomCell , Table
4
+ import matplotlib .pyplot as plt
5
+ import matplotlib as mpl
6
6
from matplotlib .path import Path
7
+ from matplotlib .table import CustomCell , Table
8
+ from matplotlib .testing .decorators import image_comparison , check_figures_equal
7
9
from matplotlib .transforms import Bbox
8
10
9
11
@@ -176,7 +178,12 @@ def test_auto_column():
176
178
loc = "center" )
177
179
tb4 .auto_set_font_size (False )
178
180
tb4 .set_fontsize (12 )
179
- tb4 .auto_set_column_width ("-101" )
181
+ with pytest .warns (mpl .MatplotlibDeprecationWarning ,
182
+ match = "'col' must be an int or sequence of ints" ):
183
+ tb4 .auto_set_column_width ("-101" ) # type: ignore [arg-type]
184
+ with pytest .warns (mpl .MatplotlibDeprecationWarning ,
185
+ match = "'col' must be an int or sequence of ints" ):
186
+ tb4 .auto_set_column_width (["-101" ]) # type: ignore [list-item]
180
187
181
188
182
189
def test_table_cells ():
You can’t perform that action at this time.
0 commit comments