Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 05a66bb

Browse files
masihkhatibzadeh99masih.khatibzdeh
and
masih.khatibzdeh
authored
Fix: Ensure ScalarFormatter.set_useOffset properly distinguishes betw… (#29537)
* Fix: Ensure ScalarFormatter.set_useOffset properly distinguishes between booleans and numeric values * fix: flake8 lint issue --------- Co-authored-by: masih.khatibzdeh <[email protected]>
1 parent 91d115e commit 05a66bb

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,22 @@ def test_set_use_offset_float(self):
859859
assert not tmp_form.get_useOffset()
860860
assert tmp_form.offset == 0.5
861861

862+
def test_set_use_offset_bool(self):
863+
tmp_form = mticker.ScalarFormatter()
864+
tmp_form.set_useOffset(True)
865+
assert tmp_form.get_useOffset()
866+
assert tmp_form.offset == 0
867+
868+
tmp_form.set_useOffset(False)
869+
assert not tmp_form.get_useOffset()
870+
assert tmp_form.offset == 0
871+
872+
def test_set_use_offset_int(self):
873+
tmp_form = mticker.ScalarFormatter()
874+
tmp_form.set_useOffset(1)
875+
assert not tmp_form.get_useOffset()
876+
assert tmp_form.offset == 1
877+
862878
def test_use_locale(self):
863879
conv = locale.localeconv()
864880
sep = conv['thousands_sep']

lib/matplotlib/ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def set_useOffset(self, val):
510510
will be formatted as ``0, 2, 4, 6, 8`` plus an offset ``+1e5``, which
511511
is written to the edge of the axis.
512512
"""
513-
if val in [True, False]:
513+
if isinstance(val, bool):
514514
self.offset = 0
515515
self._useOffset = val
516516
else:

0 commit comments

Comments
 (0)