Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from pydata:main #634

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Bug fixes
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
- Use zarr-fixture to prevent thread leakage errors (:pull:`9967`).
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
- Fix weighted ``polyfit`` for arrays with more than two dimensions (:issue:`9972`, :pull:`9974`).
By `Mattia Almansi <https://github.com/malmans2>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9206,7 +9206,7 @@ def polyfit(

present_dims.update(other_dims)
if w is not None:
rhs = rhs * w[:, np.newaxis]
rhs = rhs * w.reshape(-1, *((1,) * len(other_dims)))

with warnings.catch_warnings():
if full: # Copy np.polyfit behavior
Expand Down
8 changes: 6 additions & 2 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6685,11 +6685,15 @@ def test_polyfit_output(self) -> None:
assert len(out.data_vars) == 0

def test_polyfit_weighted(self) -> None:
# Make sure weighted polyfit does not change the original object (issue #5644)
ds = create_test_data(seed=1)
ds = ds.broadcast_like(ds) # test more than 2 dimensions (issue #9972)
ds_copy = ds.copy(deep=True)

ds.polyfit("dim2", 2, w=np.arange(ds.sizes["dim2"]))
expected = ds.polyfit("dim2", 2)
actual = ds.polyfit("dim2", 2, w=np.ones(ds.sizes["dim2"]))
xr.testing.assert_identical(expected, actual)

# Make sure weighted polyfit does not change the original object (issue #5644)
xr.testing.assert_identical(ds, ds_copy)

def test_polyfit_coord(self) -> None:
Expand Down
8 changes: 6 additions & 2 deletions xarray/tests/test_datatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,8 +1240,12 @@ def test_repr_inherited_dims(self) -> None:
)
def test_doc_example(self) -> None:
# regression test for https://github.com/pydata/xarray/issues/9499
time = xr.DataArray(data=["2022-01", "2023-01"], dims="time")
stations = xr.DataArray(data=list("abcdef"), dims="station")
time = xr.DataArray(
data=np.array(["2022-01", "2023-01"], dtype="<U7"), dims="time"
)
stations = xr.DataArray(
data=np.array(list("abcdef"), dtype="<U1"), dims="station"
)
lon = [-100, -80, -60]
lat = [10, 20, 30]
# Set up fake data
Expand Down