File tree Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ Performance
42
42
43
43
Bug fixes
44
44
~~~~~~~~~
45
+ - Fix bug where weighted ``polyfit `` were changing the original object (:issue: `5644 `, :pull: `7900 `).
46
+ By `Mattia Almansi <https://github.com/malmans2 >`_.
45
47
- Don't call ``CachingFileManager.__del__ `` on interpreter shutdown (:issue: `7814 `, :pull: `7880 `).
46
48
By `Justus Magin <https://github.com/keewis >`_.
47
49
Original file line number Diff line number Diff line change @@ -7972,7 +7972,7 @@ def polyfit(
7972
7972
scale_da = scale
7973
7973
7974
7974
if w is not None :
7975
- rhs *= w [:, np .newaxis ]
7975
+ rhs = rhs * w [:, np .newaxis ]
7976
7976
7977
7977
with warnings .catch_warnings ():
7978
7978
if full : # Copy np.polyfit behavior
Original file line number Diff line number Diff line change @@ -6217,6 +6217,14 @@ def test_polyfit_output(self) -> None:
6217
6217
out = ds .polyfit ("time" , 2 )
6218
6218
assert len (out .data_vars ) == 0
6219
6219
6220
+ def test_polyfit_weighted (self ) -> None :
6221
+ # Make sure weighted polyfit does not change the original object (issue #5644)
6222
+ ds = create_test_data (seed = 1 )
6223
+ ds_copy = ds .copy (deep = True )
6224
+
6225
+ ds .polyfit ("dim2" , 2 , w = np .arange (ds .sizes ["dim2" ]))
6226
+ xr .testing .assert_identical (ds , ds_copy )
6227
+
6220
6228
def test_polyfit_warnings (self ) -> None :
6221
6229
ds = create_test_data (seed = 1 )
6222
6230
You can’t perform that action at this time.
0 commit comments