Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbb44ab3

Browse files
committed
ENH: Add test for masked units behavior
1 parenta921eb6 commitbb44ab3

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
importmatplotlib.pyplotasplt
2+
frommatplotlib.testing.decoratorsimportimage_comparison
23
importmatplotlib.unitsasmunits
34
importnumpyasnp
45

@@ -9,24 +10,25 @@
910
frommockimportMagicMock
1011

1112

12-
# Tests that the conversion machinery works properly for classes that
13-
# work as a facade over numpy arrays (like pint)
14-
deftest_numpy_facade():
15-
# Basic class that wraps numpy array and has units
16-
classQuantity(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+
classQuantity(object):
15+
def__init__(self,data,units):
16+
self.magnitude=data
17+
self.units=units
2018

21-
defto(self,new_units):
22-
returnQuantity(self.magnitude,new_units)
19+
defto(self,new_units):
20+
returnQuantity(self.magnitude,new_units)
2321

24-
def__getattr__(self,attr):
25-
returngetattr(self.magnitude,attr)
22+
def__getattr__(self,attr):
23+
returngetattr(self.magnitude,attr)
2624

27-
def__getitem__(self,item):
28-
returnself.magnitude[item]
25+
def__getitem__(self,item):
26+
returnself.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+
deftest_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
assertqc.convert.called
5658
assertqc.axisinfo.called
5759
assertqc.default_units.called
60+
61+
62+
# Tests gh-8908
63+
@image_comparison(baseline_images=['plot_masked_units'],
64+
extensions=['png'],remove_text=True)
65+
deftest_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)

[8]ページ先頭

©2009-2025 Movatter.jp