Skip to content

to_dataset should preserve source dim order without test-side sortby #171

Description

@ghostiee-11

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions