Skip to content

Commit 6823d10

Browse files
anntzerdstansby
authored andcommitted
Kill _string_to_bool.
1 parent 3dcc1dc commit 6823d10

File tree

6 files changed

+15
-35
lines changed

6 files changed

+15
-35
lines changed

doc/api/next_api_changes/2018-09-18-AL-removals.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ The following deprecated APIs were removed:
1919
``GridSpecFromSubplotSpec.get_subplot_params``,
2020
- svgfont support (in :rc:`svg.fonttype`),
2121
- passing 'box-forced' to `axes.Axes.set_adjustable`,
22+
- support for the strings 'on'/'true'/'off'/'false' to mean True/False (the
23+
following functions are affected: `Axes.grid`, `Axes3D.grid`,
24+
`Axis.set_tick_params`, `pyplot.box`),

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
import matplotlib
1313

1414
from matplotlib import cbook, rcParams
15-
from matplotlib.cbook import (
16-
_OrderedSet, _check_1d, _string_to_bool, index_of, get_label)
15+
from matplotlib.cbook import _OrderedSet, _check_1d, index_of, get_label
1716
from matplotlib import docstring
1817
import matplotlib.colors as mcolors
1918
import matplotlib.lines as mlines
@@ -2729,9 +2728,6 @@ def grid(self, b=None, which='major', axis='both', **kwargs):
27292728
"""
27302729
if len(kwargs):
27312730
b = True
2732-
elif b is not None:
2733-
b = _string_to_bool(b)
2734-
27352731
if axis not in ['x', 'y', 'both']:
27362732
raise ValueError("The argument 'axis' must be one of 'x', 'y' or "
27372733
"'both'.")

lib/matplotlib/axis.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from matplotlib import rcParams
1212
import matplotlib.artist as martist
1313
import matplotlib.cbook as cbook
14-
from matplotlib.cbook import _string_to_bool
1514
import matplotlib.font_manager as font_manager
1615
import matplotlib.lines as mlines
1716
import matplotlib.patches as mpatches
@@ -845,8 +844,7 @@ def set_tick_params(self, which='major', reset=False, **kw):
845844

846845
@staticmethod
847846
def _translate_tick_kw(kw):
848-
# The following lists may be moved to a more
849-
# accessible location.
847+
# The following lists may be moved to a more accessible location.
850848
kwkeys = ['size', 'width', 'color', 'tickdir', 'pad',
851849
'labelsize', 'labelcolor', 'zorder', 'gridOn',
852850
'tick1On', 'tick2On', 'label1On', 'label2On',
@@ -861,21 +859,21 @@ def _translate_tick_kw(kw):
861859
if 'rotation' in kw:
862860
kwtrans['labelrotation'] = kw.pop('rotation')
863861
if 'left' in kw:
864-
kwtrans['tick1On'] = _string_to_bool(kw.pop('left'))
862+
kwtrans['tick1On'] = kw.pop('left')
865863
if 'bottom' in kw:
866-
kwtrans['tick1On'] = _string_to_bool(kw.pop('bottom'))
864+
kwtrans['tick1On'] = kw.pop('bottom')
867865
if 'right' in kw:
868-
kwtrans['tick2On'] = _string_to_bool(kw.pop('right'))
866+
kwtrans['tick2On'] = kw.pop('right')
869867
if 'top' in kw:
870-
kwtrans['tick2On'] = _string_to_bool(kw.pop('top'))
868+
kwtrans['tick2On'] = kw.pop('top')
871869
if 'labelleft' in kw:
872-
kwtrans['label1On'] = _string_to_bool(kw.pop('labelleft'))
870+
kwtrans['label1On'] = kw.pop('labelleft')
873871
if 'labelbottom' in kw:
874-
kwtrans['label1On'] = _string_to_bool(kw.pop('labelbottom'))
872+
kwtrans['label1On'] = kw.pop('labelbottom')
875873
if 'labelright' in kw:
876-
kwtrans['label2On'] = _string_to_bool(kw.pop('labelright'))
874+
kwtrans['label2On'] = kw.pop('labelright')
877875
if 'labeltop' in kw:
878-
kwtrans['label2On'] = _string_to_bool(kw.pop('labeltop'))
876+
kwtrans['label2On'] = kw.pop('labeltop')
879877
if 'colors' in kw:
880878
c = kw.pop('colors')
881879
kwtrans['color'] = c

lib/matplotlib/cbook/__init__.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -416,21 +416,6 @@ def is_scalar_or_string(val):
416416
return isinstance(val, str) or not np.iterable(val)
417417

418418

419-
def _string_to_bool(s):
420-
"""Parses the string argument as a boolean"""
421-
if not isinstance(s, str):
422-
return bool(s)
423-
warn_deprecated("2.2", "Passing one of 'on', 'true', 'off', 'false' as a "
424-
"boolean is deprecated; use an actual boolean "
425-
"(True/False) instead.")
426-
if s.lower() in ['on', 'true']:
427-
return True
428-
if s.lower() in ['off', 'false']:
429-
return False
430-
raise ValueError('String "%s" must be one of: '
431-
'"on", "off", "true", or "false"' % s)
432-
433-
434419
def get_sample_data(fname, asfileobj=True):
435420
"""
436421
Return a sample data file. *fname* is a path relative to the

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
import matplotlib.image
3434
from matplotlib import rcsetup, style
3535
from matplotlib import _pylab_helpers, interactive
36-
from matplotlib.cbook import (
37-
dedent, deprecated, silent_list, warn_deprecated, _string_to_bool)
36+
from matplotlib.cbook import dedent, deprecated, silent_list, warn_deprecated
3837
from matplotlib import docstring
3938
from matplotlib.backend_bases import FigureCanvasBase
4039
from matplotlib.figure import Figure, figaspect
@@ -1358,7 +1357,6 @@ def box(on=None):
13581357
ax = gca()
13591358
if on is None:
13601359
on = not ax.get_frame_on()
1361-
on = _string_to_bool(on)
13621360
ax.set_frame_on(on)
13631361

13641362
## Axis ##

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ def grid(self, b=True, **kwargs):
13001300
# TODO: Operate on each axes separately
13011301
if len(kwargs):
13021302
b = True
1303-
self._draw_grid = cbook._string_to_bool(b)
1303+
self._draw_grid = b
13041304
self.stale = True
13051305

13061306
def ticklabel_format(

0 commit comments

Comments
 (0)