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

Draft: Extend idxmin and idxmax to accept multiple dimensions #10125

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

max-sixty
Copy link
Collaborator

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

max-sixty and others added 2 commits March 14, 2025 01:32
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
@max-sixty max-sixty changed the title Extend idxmin and idxmax to accept a multiple dimensions Extend idxmin and idxmax to accept multiple dimensions Mar 14, 2025
Comment on lines +5986 to +5990
>>> array.idxmin(dim=["x", "y"])
{'x': <xarray.DataArray 'x' ()> Size: 8B
array(0.),
'y': <xarray.DataArray 'y' ()> Size: 8B
array(0)}
Copy link
Member

@shoyer shoyer Mar 14, 2025

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.

Copy link
Collaborator Author

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

Comment on lines +6004 to +6009
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,
)
Copy link
Member

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?

@max-sixty max-sixty changed the title Extend idxmin and idxmax to accept multiple dimensions Draft: Extend idxmin and idxmax to accept multiple dimensions Mar 14, 2025
@max-sixty max-sixty marked this pull request as draft March 14, 2025 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants