xarray icon indicating copy to clipboard operation
xarray copied to clipboard

Overload DataArray's argmin and argmax methods on dim parameter

Open cfriedland5 opened this issue 3 months ago • 1 comments

Is your feature request related to a problem?

DataArray's argmin and argmax methods currently have a return type of Self | dict[Hashable, Self]. However, based on the argument provided to dim I know which element of the union it will be, making the return value less convenient to type check than it could be (e.g., requires casting or type checker suppression comments).

Describe the solution you'd like

Provide overloads for the methods that give a more specific return type depending on the type of the argument to dim.

Describe alternatives you've considered

No response

Additional context

No response

cfriedland5 avatar Nov 03 '25 23:11 cfriedland5

There is the trap where str is a subtype of Collection[str] to watch out for, but since type checkers are supposed to select the first matching overload this improvement should be feasible.

cfriedland5 avatar Nov 03 '25 23:11 cfriedland5