Skip to content

Commit 6fda1aa

Browse files
committed
Kill _string_to_bool.
1 parent 1bf2111 commit 6fda1aa

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
@@ -11,8 +11,7 @@
1111
import matplotlib
1212

1313
from matplotlib import cbook, rcParams
14-
from matplotlib.cbook import (
15-
_OrderedSet, _check_1d, _string_to_bool, index_of, get_label)
14+
from matplotlib.cbook import _OrderedSet, _check_1d, index_of, get_label
1615
from matplotlib import docstring
1716
import matplotlib.colors as mcolors
1817
import matplotlib.lines as mlines
@@ -2724,9 +2723,6 @@ def grid(self, b=None, which='major', axis='both', **kwargs):
27242723
"""
27252724
if len(kwargs):
27262725
b = True
2727-
elif b is not None:
2728-
b = _string_to_bool(b)
2729-
27302726
if axis not in ['x', 'y', 'both']:
27312727
raise ValueError("The argument 'axis' must be one of 'x', 'y' or "
27322728
"'both'.")

lib/matplotlib/axis.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from matplotlib import rcParams
1111
import matplotlib.artist as martist
1212
import matplotlib.cbook as cbook
13-
from matplotlib.cbook import _string_to_bool
1413
import matplotlib.font_manager as font_manager
1514
import matplotlib.lines as mlines
1615
import matplotlib.scale as mscale
@@ -843,8 +842,7 @@ def set_tick_params(self, which='major', reset=False, **kw):
843842

844843
@staticmethod
845844
def _translate_tick_kw(kw):
846-
# The following lists may be moved to a more
847-
# accessible location.
845+
# The following lists may be moved to a more accessible location.
848846
kwkeys = ['size', 'width', 'color', 'tickdir', 'pad',
849847
'labelsize', 'labelcolor', 'zorder', 'gridOn',
850848
'tick1On', 'tick2On', 'label1On', 'label2On',
@@ -859,21 +857,21 @@ def _translate_tick_kw(kw):
859857
if 'rotation' in kw:
860858
kwtrans['labelrotation'] = kw.pop('rotation')
861859
if 'left' in kw:
862-
kwtrans['tick1On'] = _string_to_bool(kw.pop('left'))
860+
kwtrans['tick1On'] = kw.pop('left')
863861
if 'bottom' in kw:
864-
kwtrans['tick1On'] = _string_to_bool(kw.pop('bottom'))
862+
kwtrans['tick1On'] = kw.pop('bottom')
865863
if 'right' in kw:
866-
kwtrans['tick2On'] = _string_to_bool(kw.pop('right'))
864+
kwtrans['tick2On'] = kw.pop('right')
867865
if 'top' in kw:
868-
kwtrans['tick2On'] = _string_to_bool(kw.pop('top'))
866+
kwtrans['tick2On'] = kw.pop('top')
869867
if 'labelleft' in kw:
870-
kwtrans['label1On'] = _string_to_bool(kw.pop('labelleft'))
868+
kwtrans['label1On'] = kw.pop('labelleft')
871869
if 'labelbottom' in kw:
872-
kwtrans['label1On'] = _string_to_bool(kw.pop('labelbottom'))
870+
kwtrans['label1On'] = kw.pop('labelbottom')
873871
if 'labelright' in kw:
874-
kwtrans['label2On'] = _string_to_bool(kw.pop('labelright'))
872+
kwtrans['label2On'] = kw.pop('labelright')
875873
if 'labeltop' in kw:
876-
kwtrans['label2On'] = _string_to_bool(kw.pop('labeltop'))
874+
kwtrans['label2On'] = kw.pop('labeltop')
877875
if 'colors' in kw:
878876
c = kw.pop('colors')
879877
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,9 +33,8 @@
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)
3836
from matplotlib import cbook
37+
from matplotlib.cbook import dedent, deprecated, silent_list, warn_deprecated
3938
from matplotlib import docstring
4039
from matplotlib.backend_bases import FigureCanvasBase
4140
from matplotlib.figure import Figure, figaspect
@@ -1361,7 +1360,6 @@ def box(on=None):
13611360
ax = gca()
13621361
if on is None:
13631362
on = not ax.get_frame_on()
1364-
on = _string_to_bool(on)
13651363
ax.set_frame_on(on)
13661364

13671365
## Axis ##

lib/mpl_toolkits/mplot3d/axes3d.py

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

13091309
def ticklabel_format(

0 commit comments

Comments
 (0)