-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Draft: Extend idxmin
and idxmax
to accept multiple dimensions
#10125
base: main
Are you sure you want to change the base?
Conversation
fhis was almost totally done by Claude Code (though our files are super-inefficient, such that it used 17M tokens! which still only costs $8.44 but I guess it could be a couple of orders of magnitude less than that) my main contribution was trying to find a better way to express the: ``` if (dim is ... or (isinstance(dim, Iterable) and not isinstance(dim, str))) and not isinstance( dim, tuple ): ``` we seem to have a lot of functions which touch on this: `infix_dims`, `parse_ordered_dims` (which only seems to be called in our tests?!), `parse_dims_as_tuple`, `parse_dims_as_set`. Let me know if there's a recommended way
for more information, see https://pre-commit.ci
idxmin
and idxmax
to accept a multiple dimensionsidxmin
and idxmax
to accept multiple dimensions
>>> array.idxmin(dim=["x", "y"]) | ||
{'x': <xarray.DataArray 'x' ()> Size: 8B | ||
array(0.), | ||
'y': <xarray.DataArray 'y' ()> Size: 8B | ||
array(0)} |
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.
This example looks right to me, but does the code actually implement this behavior?
The unit tests don't include anything like this. 2d idxmin looks like it reduces over each dimension independently, and would return a dict of 1D results.
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.
Sorry, I think my doctest run didn't work, you're right.
Moving this to draft
result[k] = self.idxmin( | ||
dim=k, # type: ignore[arg-type] # k is Hashable from self.dims | ||
skipna=skipna, | ||
fill_value=fill_value, | ||
keep_attrs=keep_attrs, | ||
) |
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.
Shouldn't this be a recursive call to idxmin of some kind?
idxmin
and idxmax
to accept multiple dimensionsidxmin
and idxmax
to accept multiple dimensions
fhis was almost totally done by Claude Code (though our files are super-inefficient, such that it used 17M tokens! which still only costs $8.44 but I guess it could be a couple of orders of magnitude less than that)
my main contribution was trying to find a better way to express the:
we seem to have a lot of functions which touch on this:
infix_dims
,parse_ordered_dims
(which only seems to be called in our tests?!),parse_dims_as_tuple
,parse_dims_as_set
. Let me know if there's a recommended way