Skip to content

Commit 103ead1

Browse files
committed
BUG: Fixed test errors
PEP8 in tests Forgot conversion to int in Binary- and HexIntFormatters.
1 parent 53893d0 commit 103ead1

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lib/matplotlib/tests/test_ticker.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ def test_BinaryIntFormatter(n, unsigned, value, expected):
565565
assert fmt(value) == expected
566566

567567

568-
@pytest.mark.parametrize('n, unsigned, value, expected',[
568+
@pytest.mark.parametrize('n, unsigned, value, expected', [
569569
# Positive, <4 digits
570570
(4, False, 37, '0025'),
571571
(4, True, 37, '0025'),
@@ -603,19 +603,20 @@ def test_LinearScaleFormatter():
603603
Verifies that the linear transformations are being done correctly.
604604
"""
605605
# Make a formatter that truncates to two decimal places always
606-
base = lambda x, pos=None: '{:0.2f}'.format(x)
606+
def baseFormatter(x, pos=None):
607+
return '{:0.2f}'.format(x)
607608

608609
inputs = np.arange(-2.5, 13, 2.5)
609610
outputs = ['{:0.2f}'.format(x) for x in np.arange(7.0)]
610611

611612
# Check a simple case
612-
fmt = mticker.LinearScaleFormatter(10, (1, 5), formatter=base)
613+
fmt = mticker.LinearScaleFormatter(10, (1, 5), formatter=baseFormatter)
613614
for i, o in zip(inputs, outputs):
614615
print(i, fmt(i), o)
615616
assert fmt(i) == o
616617

617618
# Check a reverse mapping
618-
fmt = mticker.LinearScaleFormatter(10, (5, 1), formatter=base)
619+
fmt = mticker.LinearScaleFormatter(10, (5, 1), formatter=baseFormatter)
619620
for i, o in zip(inputs, reversed(outputs)):
620621
print(i, fmt(i), o)
621622
assert fmt(i) == o

lib/matplotlib/ticker.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1319,11 +1319,12 @@ class BinaryIntFormatter(Formatter):
13191319
with a `MaxNLocator` with ``integer=True``.
13201320
"""
13211321
def __init__(self, n, unsigned=False):
1322-
self.n = n
1322+
self.n = int(n)
13231323
self.unsigned = unsigned
13241324

13251325
def format(self, x):
13261326
n = self.n
1327+
x = int(x)
13271328
if x < 0:
13281329
if self.unsigned:
13291330
x = x & ((1 << n) - 1)
@@ -1352,11 +1353,12 @@ class HexIntFormatter(Formatter):
13521353
used with a `MaxNLocator` with ``integer=True``.
13531354
"""
13541355
def __init__(self, n, unsigned=False):
1355-
self.n = n
1356+
self.n = int(n)
13561357
self.unsigned = unsigned
13571358

13581359
def format(self, x):
13591360
n = self.n
1361+
x = int(x)
13601362
if x < 0:
13611363
if self.unsigned:
13621364
x = x & ((1 << (4 * n)) - 1)
@@ -1416,7 +1418,7 @@ def transform(self, x):
14161418
"""
14171419
Transforms a value from the input scale to the output scale.
14181420
"""
1419-
return (x - self.iMin) / self.iRange * self.oRange + self.oMin
1421+
return (x - self.iMin) / self.iRange * self.oRange + self.oMin
14201422

14211423
def __call__(self, x, pos=None):
14221424
return self.formatter(self.transform(x), pos)

0 commit comments

Comments
 (0)