MCPcopy Index your code
hub / github.com/pydata/xarray / __init__

Method __init__

xarray/core/dataarray.py:416–478  ·  view source on GitHub ↗
(
        self,
        data: Any = dtypes.NA,
        coords: (
            Sequence[Sequence | pd.Index | DataArray | Variable | np.ndarray]
            | Mapping
            | None
        ) = None,
        dims: str | Iterable[Hashable] | None = None,
        name: Hashable | None = None,
        attrs: Mapping | None = None,
        # internal parameters
        indexes: Mapping[Hashable, Index] | None = None,
        fastpath: bool = False,
    )

Source from the content-addressed store, hash-verified

414 dt = utils.UncachedAccessor(CombinedDatetimelikeAccessor["DataArray"])
415
416 def __init__(
417 self,
418 data: Any = dtypes.NA,
419 coords: (
420 Sequence[Sequence | pd.Index | DataArray | Variable | np.ndarray]
421 | Mapping
422 | None
423 ) = None,
424 dims: str | Iterable[Hashable] | None = None,
425 name: Hashable | None = None,
426 attrs: Mapping | None = None,
427 # internal parameters
428 indexes: Mapping[Hashable, Index] | None = None,
429 fastpath: bool = False,
430 ) -> None:
431 if fastpath:
432 variable = data
433 assert dims is None
434 assert attrs is None
435 assert indexes is not None
436 else:
437 if indexes is not None:
438 raise ValueError(
439 "Explicitly passing indexes via the `indexes` argument is not supported "
440 "when `fastpath=False`. Use the `coords` argument instead."
441 )
442
443 # try to fill in arguments from data if they weren't supplied
444 if coords is None:
445 if isinstance(data, DataArray):
446 coords = data.coords
447 elif isinstance(data, pd.Series):
448 coords = [data.index]
449 elif isinstance(data, pd.DataFrame):
450 coords = [data.index, data.columns]
451 elif isinstance(data, pd.Index | IndexVariable):
452 coords = [data]
453
454 if dims is None:
455 dims = getattr(data, "dims", getattr(coords, "dims", None))
456 if name is None:
457 name = getattr(data, "name", None)
458 if attrs is None and not isinstance(data, PANDAS_TYPES):
459 attrs = getattr(data, "attrs", None)
460
461 data = _check_data_shape(data, coords, dims)
462 data = as_compatible_data(data)
463 coords, dims = _infer_coords_and_dims(data.shape, coords, dims)
464 variable = Variable(dims, data, attrs, fastpath=True)
465
466 if not isinstance(coords, Coordinates):
467 coords = create_coords_with_default_indexes(coords)
468 indexes = dict(coords.xindexes)
469 coords = {k: v.copy() for k, v in coords.variables.items()}
470
471 # These fully describe a DataArray
472 self._variable = variable
473 assert isinstance(coords, dict)

Callers

nothing calls this directly

Calls 7

as_compatible_dataFunction · 0.90
VariableClass · 0.90
_check_data_shapeFunction · 0.85
_infer_coords_and_dimsFunction · 0.85
itemsMethod · 0.80
copyMethod · 0.45

Tested by

no test coverage detected