pint-xarray icon indicating copy to clipboard operation
pint-xarray copied to clipboard

recreating indexes after conversion

Open keewis opened this issue 1 year ago • 3 comments

@benbovy, do you have any idea about how to best do this? from_variables is a class method, so it won't preserve any options that were already on the index, even if we don't pass an empty dict. This shouldn't block this PR, though.

Originally posted by @keewis in https://github.com/xarray-contrib/pint-xarray/pull/163#discussion_r1669996550

I'm afraid there is no easy way of converting units (i.e, new coordinate values + re-create the underlying index + wrap it as a new PintIndex) that would be completely agnostic of the underlying index type.

Actually I would rather drop the index and let the user re-create it manually. This is also better behavior for custom indexes that may be expensive to build (e.g., a KDTree).

For convenience we might also choose to auto-convert indexes for Xarray built-in index types only (and pass the options in a hard-coded way, if any... currently PandasIndex and PandasMultiIndex do not expose any option).

Originally posted by @benbovy in https://github.com/xarray-contrib/pint-xarray/pull/163#discussion_r1670068233

keewis avatar Jul 09 '24 09:07 keewis