Skip to content

Commit

Permalink
add test for weight transposing case
Browse files Browse the repository at this point in the history
  • Loading branch information
rcomer committed Dec 15, 2023
1 parent ad93a3e commit 4ac142b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/iris/tests/unit/analysis/stats/test_pearsonr.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ def test_broadcast_cubes_weighted(self):
]
self.assertArrayAlmostEqual(r.data, np.array(r_by_slice))

def test_broadcast_transpose_cubes_weighted(self):
# Reference is calculated with no transposition.
r_ref = stats.pearsonr(
self.cube_a,
self.cube_b[0, :, :],
["latitude", "longitude"],
weights=self.weights[0, :, :],
)

self.cube_a.transpose()
r_test = stats.pearsonr(
self.cube_a,
self.cube_b[0, :, :],
["latitude", "longitude"],
weights=self.weights[0, :, :],
)

# Should get the same result, but transposed.
self.assertArrayAlmostEqual(r_test.data, r_ref.data.T)

def test_weight_error(self):
with self.assertRaises(ValueError):
stats.pearsonr(
Expand Down

0 comments on commit 4ac142b

Please sign in to comment.