File tree Expand file tree Collapse file tree 3 files changed +27
-12
lines changed
doc/api/next_api_changes/deprecations Expand file tree Collapse file tree 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 2424Thanks to John Gill for providing the class and table.
2525"""
2626
27+ import numpy as np
28+
2729from . import _api , _docstring
2830from .artist import Artist , allow_rasterization
2931from .patches import Rectangle
@@ -494,14 +496,15 @@ def auto_set_column_width(self, col):
494496 col : int or sequence of ints
495497 The indices of the columns to auto-scale.
496498 """
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 )
505508
506509 self .stale = True
507510
Original file line number Diff line number Diff line change 1- import matplotlib .pyplot as plt
21import numpy as np
3- from matplotlib . testing . decorators import image_comparison , check_figures_equal
2+ import pytest
43
5- from matplotlib .table import CustomCell , Table
4+ import matplotlib .pyplot as plt
5+ import matplotlib as mpl
66from matplotlib .path import Path
7+ from matplotlib .table import CustomCell , Table
8+ from matplotlib .testing .decorators import image_comparison , check_figures_equal
79from matplotlib .transforms import Bbox
810
911
@@ -176,7 +178,12 @@ def test_auto_column():
176178 loc = "center" )
177179 tb4 .auto_set_font_size (False )
178180 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]
180187
181188
182189def test_table_cells ():
You can’t perform that action at this time.
0 commit comments