You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
xarray: Use Dataset.sizes instead of Dataset.dims #3333
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.
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.
Activity
[-]xarray: Use Dataset.sizes() instead of Dataset.dims()[/-][+]xarray: Use Dataset.sizes instead of Dataset.dims[/+]ekluzek commentedon Jul 24, 2025
Adding next to discuss this as a habit to start doing.
samsrabin commentedon Jul 24, 2025
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.