MCPcopy
hub / github.com/pydata/xarray / __init__

Method __init__

xarray/core/coordinates.py:292–355  ·  view source on GitHub ↗
(
        self,
        coords: Mapping[Any, Any] | None = None,
        indexes: Mapping[Any, Index] | None = None,
    )

Source from the content-addressed store, hash-verified

290 __slots__ = ("_data",)
291
292 def __init__(
293 self,
294 coords: Mapping[Any, Any] | None = None,
295 indexes: Mapping[Any, Index] | None = None,
296 ) -> None:
297 # When coordinates are constructed directly, an internal Dataset is
298 # created so that it is compatible with the DatasetCoordinates and
299 # DataArrayCoordinates classes serving as a proxy for the data.
300 # TODO: refactor DataArray / Dataset so that Coordinates store the data.
301 from xarray.core.dataset import Dataset
302
303 if coords is None:
304 coords = {}
305
306 variables: dict[Hashable, Variable]
307 default_indexes: dict[Hashable, PandasIndex] = {}
308 coords_obj_indexes: dict[Hashable, Index] = {}
309
310 if isinstance(coords, Coordinates):
311 if indexes is not None:
312 raise ValueError(
313 "passing both a ``Coordinates`` object and a mapping of indexes "
314 "to ``Coordinates.__init__`` is not allowed "
315 "(this constructor does not support merging them)"
316 )
317 variables = {k: v.copy() for k, v in coords.variables.items()}
318 coords_obj_indexes = dict(coords.xindexes)
319 else:
320 variables = {}
321 for name, data in coords.items():
322 var = as_variable(data, name=name, auto_convert=False)
323 if var.dims == (name,) and indexes is None:
324 index, index_vars = create_default_index_implicit(var, list(coords))
325 default_indexes.update(dict.fromkeys(index_vars, index))
326 variables.update(index_vars)
327 else:
328 variables[name] = var
329
330 if indexes is None:
331 indexes = {}
332 else:
333 indexes = dict(indexes)
334
335 indexes.update(default_indexes)
336 indexes.update(coords_obj_indexes)
337
338 no_coord_index = set(indexes) - set(variables)
339 if no_coord_index:
340 raise ValueError(
341 f"no coordinate variables found for these indexes: {no_coord_index}"
342 )
343
344 for k, idx in indexes.items():
345 if not isinstance(idx, Index):
346 raise TypeError(f"'{k}' is not an `xarray.indexes.Index` object")
347
348 # maybe convert to base variable
349 for k, v in variables.items():

Callers

nothing calls this directly

Calls 7

as_variableFunction · 0.90
itemsMethod · 0.80
to_base_variableMethod · 0.80
copyMethod · 0.45
updateMethod · 0.45
_construct_directMethod · 0.45

Tested by

no test coverage detected