Skip to content

Error in behaviour of cf.DimensionCoordinate.direction #859

Description

@davidhassell

The #856 it was noted that the collapsed time coordinates came out incorrectly as monotonically decreasing when cf.djf was used in the MRE, whilst using cf.mam led to the correct monotonically increasing time coordinate sequence.

It turns this is because the time coordinates in the original field do not have bounds, and in the cf.djf grouped collapse case, one of the grouped collapses has just one month in it (December 2022), with bounds that equal the coordinate value. In this case, cfdm.DimensionCoordinate._infer_direction tells us that the direction is decreasing due to the use of the strict inequalities < (https://github.com/NCAS-CMS/cf-python/blob/v3.16.3/cf/dimensioncoordinate.py#L130), when non-strict ones (<=) are intended. The decreasing information feeds its way into the sorting of the collapsed groups via reverse=coord.decreasing (https://github.com/NCAS-CMS/cf-python/blob/v3.16.3/cf/field.py#L8747).

Very short PR to follow that fixes this by simply changing the appropriate < to <=.

Activity

  1. added this to the 3.17.0 milestone on Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions