Open keewis opened 4 months ago
For convenience we might also choose to auto-convert indexes for Xarray built-in index types only
Good thing is that changing the behavior implemented in #163 (auto-convert all indexes -> drop custom indexes) won't have a great impact until we see more Xarray custom indexes in the wild. But probably best not wait too long before addressing this issue.
The problem with dropping the index is that it will require dequantifying the indexed coordinates, otherwise recreating the index would drop the units entirely.
The only ways I can see around that would be documenting this, or to add a workaround method that does the dequantify
→ set_xindex
→ quantify
cycle for the user. Either way requires user intervention, so I'm hoping we can find another way around this.
Yes a wrapper method like .pint.set_xindex()
would be useful. I don't think we would need to dequantify the coordinate(s) first, having unindexed but quantified coordinates seems ok to me and would work well with the latter method. In general some user intervention may be better than auto-magically re-building the index IMO, with some exceptions like Xarray builtin and cheap indexes.
(Note that recreating an index wouldn't always drop the coordinate units: some custom indexes may just pass through the variables in their implementation of Index.from_variables()
, even though quantified coordinates without a PintIndex
are not very useful).
_Originally posted by @keewis in https://github.com/xarray-contrib/pint-xarray/pull/163#discussion_r1669996550_
_Originally posted by @benbovy in https://github.com/xarray-contrib/pint-xarray/pull/163#discussion_r1670068233_