File tree Expand file tree Collapse file tree 3 files changed +9
-3
lines changed Expand file tree Collapse file tree 3 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ Bug fixes
71
71
By `Kai Mühlbauer <https://github.com/kmuehlbauer >`_.
72
72
- Use zarr-fixture to prevent thread leakage errors (:pull: `9967 `).
73
73
By `Kai Mühlbauer <https://github.com/kmuehlbauer >`_.
74
+ - Fix weighted ``polyfit `` for arrays with more than two dimensions (:issue: `9972 `, :pull: `9974 `).
75
+ By `Mattia Almansi <https://github.com/malmans2 >`_.
74
76
75
77
Documentation
76
78
~~~~~~~~~~~~~
Original file line number Diff line number Diff line change @@ -9206,7 +9206,7 @@ def polyfit(
9206
9206
9207
9207
present_dims .update (other_dims )
9208
9208
if w is not None :
9209
- rhs = rhs * w [:, np . newaxis ]
9209
+ rhs = rhs * w . reshape ( - 1 , * (( 1 ,) * len ( other_dims )))
9210
9210
9211
9211
with warnings .catch_warnings ():
9212
9212
if full : # Copy np.polyfit behavior
Original file line number Diff line number Diff line change @@ -6685,11 +6685,15 @@ def test_polyfit_output(self) -> None:
6685
6685
assert len (out .data_vars ) == 0
6686
6686
6687
6687
def test_polyfit_weighted (self ) -> None :
6688
- # Make sure weighted polyfit does not change the original object (issue #5644)
6689
6688
ds = create_test_data (seed = 1 )
6689
+ ds = ds .broadcast_like (ds ) # test more than 2 dimensions (issue #9972)
6690
6690
ds_copy = ds .copy (deep = True )
6691
6691
6692
- ds .polyfit ("dim2" , 2 , w = np .arange (ds .sizes ["dim2" ]))
6692
+ expected = ds .polyfit ("dim2" , 2 )
6693
+ actual = ds .polyfit ("dim2" , 2 , w = np .ones (ds .sizes ["dim2" ]))
6694
+ xr .testing .assert_identical (expected , actual )
6695
+
6696
+ # Make sure weighted polyfit does not change the original object (issue #5644)
6693
6697
xr .testing .assert_identical (ds , ds_copy )
6694
6698
6695
6699
def test_polyfit_coord (self ) -> None :
You can’t perform that action at this time.
0 commit comments