Skip to content

xarray: Use Dataset.sizes instead of Dataset.dims #3333

Description

@samsrabin

There are some places in the Python scripts where we use the dims member of Xarray Datasets in order to get dimension lengths. As of the latest ctsm_pylib (Python 3.13.2, Xarray 2025.1.2), this produces a warning (here produced from ctsm5.3.063):

modify_fsurdat.py:49: FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.
  self.numurbl = self.file.dims["numurbl"]

We should go ahead and convert all such instances to Dataset.sizes so we don't have confusing failures when we eventually update Xarray to a version with the new behavior.

Activity

  1. added this to the Eventually milestone on Jul 14, 2025
  2. added
    priority: lowBackground task that doesn't need to be done right away.
    on Jul 14, 2025
  3. added
    code healthimproving internal code structure to make easier to maintain (sustainability)
    b4bbit-for-bit
    on Jul 14, 2025
  4. changed the title [-]xarray: Use Dataset.sizes() instead of Dataset.dims()[/-] [+]xarray: Use Dataset.sizes instead of Dataset.dims[/+] on Jul 14, 2025
  5. added
    nextthis should get some attention in the next week or two. Normally each Thursday SE meeting.
    on Jul 24, 2025
  6. ekluzek commented on Jul 24, 2025

    @ekluzek
    Contributor

    Adding next to discuss this as a habit to start doing.

  7. removed
    nextthis should get some attention in the next week or two. Normally each Thursday SE meeting.
    on Jul 24, 2025
  8. samsrabin commented on Jul 24, 2025

    @samsrabin
    MemberAuthor

    It would be pretty easy to find and replace all existing instances in our Python code. Before doing that, we could also change our Python testing to turn these warnings into errors (with the warnings filter), so we don't add any more (tested) instances of this behavior.

  9. added
    test: pythonPass clm_pymods test suite plus Python sys/unit tests before merging
    on Oct 5, 2026
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

    b4bbit-for-bitcode healthimproving internal code structure to make easier to maintain (sustainability)priority: lowBackground task that doesn't need to be done right away.test: pythonPass clm_pymods test suite plus Python sys/unit tests before merging

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions