Fix groupby binary ops when grouped array is subset relative to other#7798
Merged
dcherian merged 4 commits intopydata:mainfrom May 2, 2023
Merged
Fix groupby binary ops when grouped array is subset relative to other#7798dcherian merged 4 commits intopydata:mainfrom
dcherian merged 4 commits intopydata:mainfrom
Conversation
headtr1ck
reviewed
Apr 30, 2023
Collaborator
headtr1ck
left a comment
There was a problem hiding this comment.
I think the broken test was actually wrong before, now the actual result looks more like what I would expect.
Contributor
|
Thanks for the quick fix! Not sure about the bitshift test but I'm assuming @headtr1ck is right. |
Contributor
|
Apologies, that's my bad. Looks like I introduced a broken test and didn't manually double check the results coming back. The right shift test should have been: right_expected = Dataset(
{
"x": ("index", [0, 0, 2, 2]),
"y": ("index", [-1, -1, -2, -2]),
"level": ("index", [0, 0, 4, 4]),
"index": [0, 1, 2, 3],
}
)
right_actual = (left_expected.groupby("level") >> shift).reset_coords(names="level")
assert_equal(right_expected, right_actual)I haven't paid attention to this issue, but doing the groupby manually didn't have the bug fwiw. Probably overkill test that only fails at the last assert before this fix
def test_groupby_math_bitshift() -> None:
# create new dataset of int's only
ds = Dataset(
{
"x": ("index", np.ones(4, dtype=int)),
"y": ("index", np.ones(4, dtype=int) * -1),
"level": ("index", [1, 1, 2, 2]),
"index": [0, 1, 2, 3],
}
)
shift = DataArray([1, 2, 1], [("level", [1, 2, 8])])
left_expected = Dataset(
{
"x": ("index", [2, 2, 4, 4]),
"y": ("index", [-2, -2, -4, -4]),
"level": ("index", [2, 2, 8, 8]),
"index": [0, 1, 2, 3],
}
)
left_manual = []
for lev, group in ds.groupby("level"):
shifter = shift.sel(level=lev)
left_manual.append(group << shifter)
left_actual = xr.concat(left_manual, dim="index").reset_coords(names="level")
assert_equal(left_expected, left_actual)
left_actual = (ds.groupby("level") << shift).reset_coords(names="level")
assert_equal(left_expected, left_actual)
right_expected = Dataset(
{
"x": ("index", [0, 0, 2, 2]),
"y": ("index", [-1, -1, -2, -2]),
"level": ("index", [0, 0, 4, 4]),
"index": [0, 1, 2, 3],
}
)
right_manual = []
for lev, group in left_expected.groupby("level"):
shifter = shift.sel(level=lev)
right_manual.append(group >> shifter)
right_actual = xr.concat(right_manual, dim="index").reset_coords(names="level")
assert_equal(right_expected, right_actual)
right_actual = (left_expected.groupby("level") >> shift).reset_coords(names="level")
assert_equal(right_expected, right_actual) |
dcherian
commented
May 1, 2023
Contributor
|
Would it be possible to run another bug fix release with this incorporated? Or I guess we're already on to |
dcherian
added a commit
to dcherian/xarray
that referenced
this pull request
May 6, 2023
* main: Introduce Grouper objects internally (pydata#7561) [skip-ci] Add cftime groupby, resample benchmarks (pydata#7795) Fix groupby binary ops when grouped array is subset relative to other (pydata#7798) adjust the deprecation policy for python (pydata#7793) [pre-commit.ci] pre-commit autoupdate (pydata#7803) Allow the label run-upstream to run upstream CI (pydata#7787) Update asv links in contributing guide (pydata#7801) Implement DataArray.to_dask_dataframe() (pydata#7635) `ds.to_dict` with data as arrays, not lists (pydata#7739) Add lshift and rshift operators (pydata#7741) Use canonical name for set_horizonalalignment over alias set_ha (pydata#7786) Remove pandas<2 pin (pydata#7785) [pre-commit.ci] pre-commit autoupdate (pydata#7783)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
groupbyindexing problems #7797whats-new.rstcc @slevang