-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix reindex on Dataset from MultiIndex DataFrame with RuntimeError #10381
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
base: main
Are you sure you want to change the base?
Conversation
Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @csernazs!
Just added a suggestion for the test, otherwise it looks good.
xarray/tests/test_indexes.py
Outdated
@@ -293,6 +293,35 @@ def test_reindex_like(self) -> None: | |||
with pytest.raises(ValueError, match=r".*index has duplicate values"): | |||
index3.reindex_like(index2) | |||
|
|||
def test_reindex_pandas_multiframe(self) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A simpler test for the fixed issue would something like:
def test_reindex_with_multiindex_level(self) -> None:
# test for https://github.com/pydata/xarray/issues/10347
mindex = pd.MultiIndex.from_product([[100, 200, 300], [1, 2, 3, 4]], names=["x", "y"])
y_idx = PandasIndex(mindex.levels[1], "y")
ds1 = xr.Dataset(coords={"y": [1, 2, 3]})
ds2 = xr.Dataset(coords=xr.Coordinates.from_xindex(y_idx))
actual = ds1.reindex(y=ds2.y)
assert_identical(actual, ds2)
I'd also move this test into test_dataset.py
and leave test_indexes.py
for testing the logic that is implemented in xarray.core.indexes
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @benbovy for the review!
I have implemented the test as you suggested. I put the test to the end of the file, if that's not correct, let me know.
Zsolt
Hi @benbovy , If you have time, could you please take another look at the fix? I changed the PR based on your suggestions. Thanks for all the help, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the fix and the reminder @csernazs.
whats-new.rst
api.rst