Right now XarrayDataFrame.to_dataset() discovers per-dim coords via inner_df.select(col(d)).distinct().sort(col(d).sort()), which always returns ascending values. Source Datasets whose coords are descending (e.g. air_temperature.lat runs 75 -> 15) round-trip with the lat axis flipped, and the round-trip tests have to call sortby on both sides to compare. Same for arbitrary user ordering of integer coords.
The fix is to derive coord order from the registered template when one is available, and only fall back to SELECT DISTINCT ... ORDER BY when there is no template. We would also stop sorting on dims the template already covers.
Tracking this so we can drop the sortby workarounds in tests/test_ds.py (test_round_trip_identity, test_lazy_isel_*, test_lazy_compute_returns_eager) and so users get back exactly what they registered.
Spun out of #167.
Right now
XarrayDataFrame.to_dataset()discovers per-dim coords viainner_df.select(col(d)).distinct().sort(col(d).sort()), which always returns ascending values. Source Datasets whose coords are descending (e.g.air_temperature.latruns 75 -> 15) round-trip with the lat axis flipped, and the round-trip tests have to callsortbyon both sides to compare. Same for arbitrary user ordering of integer coords.The fix is to derive coord order from the registered template when one is available, and only fall back to
SELECT DISTINCT ... ORDER BYwhen there is no template. We would also stop sorting on dims the template already covers.Tracking this so we can drop the
sortbyworkarounds intests/test_ds.py(test_round_trip_identity,test_lazy_isel_*,test_lazy_compute_returns_eager) and so users get back exactly what they registered.Spun out of #167.