24
24
from xarray .core .types import DataVars , Self , T_DataArray , T_Xarray
25
25
from xarray .core .utils import (
26
26
Frozen ,
27
+ FrozenMappingWarningOnValuesAccess ,
27
28
ReprObject ,
28
29
either_dict_or_kwargs ,
29
30
emit_user_level_warning ,
@@ -741,8 +742,8 @@ def _names(self) -> set[Hashable]:
741
742
742
743
@property
743
744
def dims (self ) -> Frozen [Hashable , int ]:
744
- # deliberately display all dims, not just those on coordinate variables - see https://github.com/pydata/xarray/issues/9466
745
- return self . _data . dims
745
+ dims = calculate_dimensions ( self . variables )
746
+ return FrozenMappingWarningOnValuesAccess ( dims )
746
747
747
748
@property
748
749
def dtypes (self ) -> Frozen [Hashable , np .dtype ]:
@@ -851,8 +852,8 @@ def _names(self) -> set[Hashable]:
851
852
852
853
@property
853
854
def dims (self ) -> Frozen [Hashable , int ]:
854
- # deliberately display all dims, not just those on coordinate variables - see https://github.com/pydata/xarray/issues/9466
855
- return Frozen ( self . _data . dims )
855
+ dims = calculate_dimensions ( self . variables )
856
+ return FrozenMappingWarningOnValuesAccess ( dims )
856
857
857
858
@property
858
859
def dtypes (self ) -> Frozen [Hashable , np .dtype ]:
@@ -942,7 +943,8 @@ def __init__(self, dataarray: T_DataArray) -> None:
942
943
943
944
@property
944
945
def dims (self ) -> tuple [Hashable , ...]:
945
- return self ._data .dims
946
+ dims = calculate_dimensions (self ._data ._coords )
947
+ return tuple (dims )
946
948
947
949
@property
948
950
def dtypes (self ) -> Frozen [Hashable , np .dtype ]:
@@ -967,7 +969,9 @@ def _update_coords(
967
969
self , coords : dict [Hashable , Variable ], indexes : dict [Hashable , Index ]
968
970
) -> None :
969
971
validate_dataarray_coords (
970
- self ._data .shape , Coordinates ._construct_direct (coords , indexes ), self .dims
972
+ self ._data .shape ,
973
+ Coordinates ._construct_direct (coords , indexes ),
974
+ self ._data .dims ,
971
975
)
972
976
973
977
self ._data ._coords = coords
0 commit comments