@@ -1768,6 +1768,27 @@ def test_all_zeros_exact(self, method):
1768
1768
res = stats .wilcoxon (np .zeros (5 ), method = method )
1769
1769
assert_allclose (res , [0 , 1 ])
1770
1770
1771
+ def test_wilcoxon_axis_broadcasting_errors_gh22051 (self ):
1772
+ # In previous versions of SciPy, `wilcoxon` gave an incorrect error
1773
+ # message when `AxisError` was not found in the base NumPy namespace.
1774
+ # Check that this is resolved with and without the ANP decorator.
1775
+ message = "Array shapes are incompatible for broadcasting."
1776
+ with pytest .raises (ValueError , match = message ):
1777
+ stats .wilcoxon ([1 , 2 , 3 ], [4 , 5 ])
1778
+
1779
+ message = "operands could not be broadcast together with..."
1780
+ with pytest .raises (ValueError , match = message ):
1781
+ stats .wilcoxon ([1 , 2 , 3 ], [4 , 5 ], _no_deco = True )
1782
+
1783
+ AxisError = getattr (np , 'AxisError' , None ) or np .exceptions .AxisError
1784
+ message = "source: axis 3 is out of bounds for array of dimension 1"
1785
+ with pytest .raises (AxisError , match = message ):
1786
+ stats .wilcoxon ([1 , 2 , 3 ], [4 , 5 , 6 ], axis = 3 )
1787
+
1788
+ message = "`axis` must be compatible with the shape..."
1789
+ with pytest .raises (AxisError , match = message ):
1790
+ stats .wilcoxon ([1 , 2 , 3 ], [4 , 5 , 6 ], axis = 3 , _no_deco = True )
1791
+
1771
1792
1772
1793
# data for k-statistics tests from
1773
1794
# https://cran.r-project.org/web/packages/kStatistics/kStatistics.pdf
0 commit comments