xarray
xarray copied to clipboard
Add parse_dims func
This PR adds a utils.parse_dims function for parsing one or more dimensions.
Currently every function that accepts multiple dimensions does this by itself.
I decided to first see if it would be useful to centralize the dimension parsing and collect inputs before adding it to other functions.
I might have thought both of them could be encapsulated in a single func... Maybe that's
infix_dims, or fine to rename!
I always thought that these two methods are incompatible. But I guess ... Is synonym for None (= all dims) and if ... Appears in an iterable, it just means replace it with all leftover dims.
I always thought that these two methods are incompatible. But I guess ... Is synonym for None (= all dims) and if ... Appears in an iterable, it just means replace it with all leftover dims.
Yes! ... is the better synonym — None is somewhat an artifact of history. So +1 for replace_none, which maybe we can gradually turn to False by default over time.
Yes!
...is the better synonym —Noneis somewhat an artifact of history. So +1 forreplace_none, which maybe we can gradually turn toFalseby default over time.
Nothing wrong with None, it is just pythons default.
The intention of replace_none=False was to leave None as None, which is important for some low level functions as they might be optimized (like numpy sum, which sums over all axes for None).
Nothing wrong with None, it is just pythons default.
The intention of
replace_none=Falsewas to leave None as None, which is important for some low level functions as they might be optimized (like numpy sum, which sums over all axes for None).
Not relevant to this PR but for background — it used to be that da.groupby() defaulted to None, and reduced all dimensions — now for a couple of years we require ....
But still da.sum() is equivalent to da.sum(...), which is arguably a bit incongruent with da.sum('a') reducing fewer dimensions than da.sum(['a','b']). But would be quite hard to change now.
For xr.dot it's also different:
xr.dot(a, b, dims=None) # reduce over common dimensions
xr.dot(a, b, dims=...) # reduce over all dimensions
I think it is best to implement two functions, one for sets of dims and one for sequences of dims. This will be easier to type/read/use than trying to put both kinds into one function.
See also #7094
Maybe parse_dims and parse_ordered_dims?