Skip to content

Commit dd8609c

Browse files
rcomerpelson
authored andcommitted
test_pearsonr: use compatible cubes for testing compatible cubes (SciTools#2960)
Pearsonr test using compatible cubes
1 parent 73220b2 commit dd8609c

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

lib/iris/tests/unit/analysis/stats/test_pearsonr.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (C) British Crown Copyright 2014 - 2017, Met Office
1+
# (C) British Crown Copyright 2014 - 2018, Met Office
22
#
33
# This file is part of Iris.
44
#
@@ -39,6 +39,7 @@ def setUp(self):
3939
('NetCDF', 'global', 'xyt', 'SMALL_total_column_co2.nc')))
4040
self.cube_a = cube_temp[0:6]
4141
self.cube_b = cube_temp[20:26]
42+
self.cube_b.replace_coord(self.cube_a.coord('time').copy())
4243
cube_temp = self.cube_a.copy()
4344
cube_temp.coord('latitude').guess_bounds()
4445
cube_temp.coord('longitude').guess_bounds()
@@ -59,15 +60,14 @@ def test_incompatible_cubes(self):
5960
'longitude')
6061

6162
def test_compatible_cubes(self):
62-
with self.assertRaises(ValueError):
63-
r = stats.pearsonr(self.cube_a, self.cube_b,
64-
['latitude', 'longitude'])
65-
self.assertArrayAlmostEqual(r.data, [0.81114936,
66-
0.81690538,
67-
0.79833135,
68-
0.81118674,
69-
0.79745386,
70-
0.81278484])
63+
r = stats.pearsonr(self.cube_a, self.cube_b,
64+
['latitude', 'longitude'])
65+
self.assertArrayAlmostEqual(r.data, [0.81114936,
66+
0.81690538,
67+
0.79833135,
68+
0.81118674,
69+
0.79745386,
70+
0.81278484])
7171

7272
def test_broadcast_cubes(self):
7373
r1 = stats.pearsonr(self.cube_a, self.cube_b[0, :, :],
@@ -82,16 +82,15 @@ def test_broadcast_cubes(self):
8282
self.assertArrayEqual(r2.data, np.array(r_by_slice))
8383

8484
def test_compatible_cubes_weighted(self):
85-
with self.assertRaises(ValueError):
86-
r = stats.pearsonr(self.cube_a, self.cube_b,
87-
['latitude', 'longitude'],
88-
self.weights)
89-
self.assertArrayAlmostEqual(r.data, [0.79106045,
90-
0.79989169,
91-
0.78826918,
92-
0.79925855,
93-
0.79011544,
94-
0.80115837])
85+
r = stats.pearsonr(self.cube_a, self.cube_b,
86+
['latitude', 'longitude'],
87+
self.weights)
88+
self.assertArrayAlmostEqual(r.data, [0.79106045,
89+
0.79989169,
90+
0.78826918,
91+
0.79925855,
92+
0.79011544,
93+
0.80115837])
9594

9695
def test_broadcast_cubes_weighted(self):
9796
r = stats.pearsonr(self.cube_a, self.cube_b[0, :, :],

0 commit comments

Comments
 (0)