Skip to content

Commit 8cf4a09

Browse files
authored
REF: use xr.Coordinates directly (#103)
1 parent f2962d4 commit 8cf4a09

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

xvec/accessor.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def is_geom_variable(
123123
return False
124124

125125
@property
126-
def geom_coords(self) -> Mapping[Hashable, xr.DataArray]:
126+
def geom_coords(self) -> xr.Coordinates:
127127
"""Returns a dictionary of xarray.DataArray objects corresponding to
128128
coordinate variables composed of :class:`shapely.Geometry` objects.
129129
@@ -168,11 +168,16 @@ def geom_coords(self) -> Mapping[Hashable, xr.DataArray]:
168168
is_geom_variable
169169
"""
170170
return xr.Coordinates(
171-
{
171+
coords={
172172
c: coo
173173
for c, coo in self._obj.coords.items()
174174
if c in self._geom_coords_all
175-
}
175+
},
176+
indexes={
177+
c: self._obj.xindexes[c]
178+
for c in self._obj.coords
179+
if c in self._geom_coords_all and c in self._obj.xindexes
180+
},
176181
)
177182

178183
@property
@@ -220,10 +225,16 @@ def geom_coords_indexed(self) -> xr.Coordinates:
220225
is_geom_variable
221226
222227
"""
223-
# TODO: use xarray.Coordinates constructor instead once available in xarray
224-
return self._obj.drop_vars(
225-
[c for c in self._obj.coords if c not in self._geom_indexes]
226-
).coords
228+
return xr.Coordinates(
229+
coords={
230+
c: coo for c, coo in self._obj.coords.items() if c in self._geom_indexes
231+
},
232+
indexes={
233+
c: self._obj.xindexes[c]
234+
for c in self._obj.coords
235+
if c in self._geom_indexes and c in self._obj.xindexes
236+
},
237+
)
227238

228239
def to_crs(
229240
self,

0 commit comments

Comments
 (0)