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

Skip to content

Commit bb44ab3

Browse files
committed
ENH: Add test for masked units behavior
1 parent a921eb6 commit bb44ab3

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

lib/matplotlib/tests/test_units.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import matplotlib.pyplot as plt
2+
from matplotlib.testing.decorators import image_comparison
23
import matplotlib.units as munits
34
import numpy as np
45

@@ -9,24 +10,25 @@
910
from mock import MagicMock
1011

1112

12-
# Tests that the conversion machinery works properly for classes that
13-
# work as a facade over numpy arrays (like pint)
14-
def test_numpy_facade():
15-
# Basic class that wraps numpy array and has units
16-
class Quantity(object):
17-
def __init__(self, data, units):
18-
self.magnitude = data
19-
self.units = units
13+
# Basic class that wraps numpy array and has units
14+
class Quantity(object):
15+
def __init__(self, data, units):
16+
self.magnitude = data
17+
self.units = units
2018

21-
def to(self, new_units):
22-
return Quantity(self.magnitude, new_units)
19+
def to(self, new_units):
20+
return Quantity(self.magnitude, new_units)
2321

24-
def __getattr__(self, attr):
25-
return getattr(self.magnitude, attr)
22+
def __getattr__(self, attr):
23+
return getattr(self.magnitude, attr)
2624

27-
def __getitem__(self, item):
28-
return self.magnitude[item]
25+
def __getitem__(self, item):
26+
return self.magnitude[item]
2927

28+
29+
# Tests that the conversion machinery works properly for classes that
30+
# work as a facade over numpy arrays (like pint)
31+
def test_numpy_facade():
3032
# Create an instance of the conversion interface and
3133
# mock so we can check methods called
3234
qc = munits.ConversionInterface()
@@ -55,3 +57,15 @@ def convert(value, unit, axis):
5557
assert qc.convert.called
5658
assert qc.axisinfo.called
5759
assert qc.default_units.called
60+
61+
62+
# Tests gh-8908
63+
@image_comparison(baseline_images=['plot_masked_units'],
64+
extensions=['png'], remove_text=True)
65+
def test_plot_masked_units():
66+
data = np.linspace(-5, 5)
67+
data_masked = np.ma.array(data, mask=(data > -2) & (data < 2))
68+
data_masked_units = Quantity(data_masked, 'meters')
69+
70+
fig, ax = plt.subplots()
71+
ax.plot(data_masked_units)

0 commit comments

Comments
 (0)