partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | IndexVariable.copy | Returns a copy of this object.
`deep` is ignored since data is stored in the form of
pandas.Index, which is already immutable. Dimensions, attributes
and encodings are always copied.
Use `data` to create a new object with the same structure as
original but entirely new data.
... | xarray/core/variable.py | def copy(self, deep=True, data=None):
"""Returns a copy of this object.
`deep` is ignored since data is stored in the form of
pandas.Index, which is already immutable. Dimensions, attributes
and encodings are always copied.
Use `data` to create a new object with the same struct... | def copy(self, deep=True, data=None):
"""Returns a copy of this object.
`deep` is ignored since data is stored in the form of
pandas.Index, which is already immutable. Dimensions, attributes
and encodings are always copied.
Use `data` to create a new object with the same struct... | [
"Returns",
"a",
"copy",
"of",
"this",
"object",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/variable.py#L1896-L1927 | [
"def",
"copy",
"(",
"self",
",",
"deep",
"=",
"True",
",",
"data",
"=",
"None",
")",
":",
"if",
"data",
"is",
"None",
":",
"data",
"=",
"self",
".",
"_data",
"else",
":",
"data",
"=",
"as_compatible_data",
"(",
"data",
")",
"if",
"self",
".",
"sh... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | IndexVariable.to_index | Convert this variable to a pandas.Index | xarray/core/variable.py | def to_index(self):
"""Convert this variable to a pandas.Index"""
# n.b. creating a new pandas.Index from an old pandas.Index is
# basically free as pandas.Index objects are immutable
assert self.ndim == 1
index = self._data.array
if isinstance(index, pd.MultiIndex):
... | def to_index(self):
"""Convert this variable to a pandas.Index"""
# n.b. creating a new pandas.Index from an old pandas.Index is
# basically free as pandas.Index objects are immutable
assert self.ndim == 1
index = self._data.array
if isinstance(index, pd.MultiIndex):
... | [
"Convert",
"this",
"variable",
"to",
"a",
"pandas",
".",
"Index"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/variable.py#L1951-L1965 | [
"def",
"to_index",
"(",
"self",
")",
":",
"# n.b. creating a new pandas.Index from an old pandas.Index is",
"# basically free as pandas.Index objects are immutable",
"assert",
"self",
".",
"ndim",
"==",
"1",
"index",
"=",
"self",
".",
"_data",
".",
"array",
"if",
"isinsta... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | IndexVariable.level_names | Return MultiIndex level names or None if this IndexVariable has no
MultiIndex. | xarray/core/variable.py | def level_names(self):
"""Return MultiIndex level names or None if this IndexVariable has no
MultiIndex.
"""
index = self.to_index()
if isinstance(index, pd.MultiIndex):
return index.names
else:
return None | def level_names(self):
"""Return MultiIndex level names or None if this IndexVariable has no
MultiIndex.
"""
index = self.to_index()
if isinstance(index, pd.MultiIndex):
return index.names
else:
return None | [
"Return",
"MultiIndex",
"level",
"names",
"or",
"None",
"if",
"this",
"IndexVariable",
"has",
"no",
"MultiIndex",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/variable.py#L1968-L1976 | [
"def",
"level_names",
"(",
"self",
")",
":",
"index",
"=",
"self",
".",
"to_index",
"(",
")",
"if",
"isinstance",
"(",
"index",
",",
"pd",
".",
"MultiIndex",
")",
":",
"return",
"index",
".",
"names",
"else",
":",
"return",
"None"
] | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | IndexVariable.get_level_variable | Return a new IndexVariable from a given MultiIndex level. | xarray/core/variable.py | def get_level_variable(self, level):
"""Return a new IndexVariable from a given MultiIndex level."""
if self.level_names is None:
raise ValueError("IndexVariable %r has no MultiIndex" % self.name)
index = self.to_index()
return type(self)(self.dims, index.get_level_values(lev... | def get_level_variable(self, level):
"""Return a new IndexVariable from a given MultiIndex level."""
if self.level_names is None:
raise ValueError("IndexVariable %r has no MultiIndex" % self.name)
index = self.to_index()
return type(self)(self.dims, index.get_level_values(lev... | [
"Return",
"a",
"new",
"IndexVariable",
"from",
"a",
"given",
"MultiIndex",
"level",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/variable.py#L1978-L1983 | [
"def",
"get_level_variable",
"(",
"self",
",",
"level",
")",
":",
"if",
"self",
".",
"level_names",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"IndexVariable %r has no MultiIndex\"",
"%",
"self",
".",
"name",
")",
"index",
"=",
"self",
".",
"to_index",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _parsed_string_to_bounds | Generalization of
pandas.tseries.index.DatetimeIndex._parsed_string_to_bounds
for use with non-standard calendars and cftime.datetime
objects. | xarray/coding/cftimeindex.py | def _parsed_string_to_bounds(date_type, resolution, parsed):
"""Generalization of
pandas.tseries.index.DatetimeIndex._parsed_string_to_bounds
for use with non-standard calendars and cftime.datetime
objects.
"""
if resolution == 'year':
return (date_type(parsed.year, 1, 1),
... | def _parsed_string_to_bounds(date_type, resolution, parsed):
"""Generalization of
pandas.tseries.index.DatetimeIndex._parsed_string_to_bounds
for use with non-standard calendars and cftime.datetime
objects.
"""
if resolution == 'year':
return (date_type(parsed.year, 1, 1),
... | [
"Generalization",
"of",
"pandas",
".",
"tseries",
".",
"index",
".",
"DatetimeIndex",
".",
"_parsed_string_to_bounds",
"for",
"use",
"with",
"non",
"-",
"standard",
"calendars",
"and",
"cftime",
".",
"datetime",
"objects",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftimeindex.py#L117-L148 | [
"def",
"_parsed_string_to_bounds",
"(",
"date_type",
",",
"resolution",
",",
"parsed",
")",
":",
"if",
"resolution",
"==",
"'year'",
":",
"return",
"(",
"date_type",
"(",
"parsed",
".",
"year",
",",
"1",
",",
"1",
")",
",",
"date_type",
"(",
"parsed",
".... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | get_date_field | Adapted from pandas.tslib.get_date_field | xarray/coding/cftimeindex.py | def get_date_field(datetimes, field):
"""Adapted from pandas.tslib.get_date_field"""
return np.array([getattr(date, field) for date in datetimes]) | def get_date_field(datetimes, field):
"""Adapted from pandas.tslib.get_date_field"""
return np.array([getattr(date, field) for date in datetimes]) | [
"Adapted",
"from",
"pandas",
".",
"tslib",
".",
"get_date_field"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftimeindex.py#L151-L153 | [
"def",
"get_date_field",
"(",
"datetimes",
",",
"field",
")",
":",
"return",
"np",
".",
"array",
"(",
"[",
"getattr",
"(",
"date",
",",
"field",
")",
"for",
"date",
"in",
"datetimes",
"]",
")"
] | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _field_accessor | Adapted from pandas.tseries.index._field_accessor | xarray/coding/cftimeindex.py | def _field_accessor(name, docstring=None, min_cftime_version='0.0'):
"""Adapted from pandas.tseries.index._field_accessor"""
def f(self, min_cftime_version=min_cftime_version):
import cftime
version = cftime.__version__
if LooseVersion(version) >= LooseVersion(min_cftime_version):
... | def _field_accessor(name, docstring=None, min_cftime_version='0.0'):
"""Adapted from pandas.tseries.index._field_accessor"""
def f(self, min_cftime_version=min_cftime_version):
import cftime
version = cftime.__version__
if LooseVersion(version) >= LooseVersion(min_cftime_version):
... | [
"Adapted",
"from",
"pandas",
".",
"tseries",
".",
"index",
".",
"_field_accessor"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftimeindex.py#L156-L174 | [
"def",
"_field_accessor",
"(",
"name",
",",
"docstring",
"=",
"None",
",",
"min_cftime_version",
"=",
"'0.0'",
")",
":",
"def",
"f",
"(",
"self",
",",
"min_cftime_version",
"=",
"min_cftime_version",
")",
":",
"import",
"cftime",
"version",
"=",
"cftime",
".... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _parse_array_of_cftime_strings | Create a numpy array from an array of strings.
For use in generating dates from strings for use with interp. Assumes the
array is either 0-dimensional or 1-dimensional.
Parameters
----------
strings : array of strings
Strings to convert to dates
date_type : cftime.datetime type
... | xarray/coding/cftimeindex.py | def _parse_array_of_cftime_strings(strings, date_type):
"""Create a numpy array from an array of strings.
For use in generating dates from strings for use with interp. Assumes the
array is either 0-dimensional or 1-dimensional.
Parameters
----------
strings : array of strings
Strings ... | def _parse_array_of_cftime_strings(strings, date_type):
"""Create a numpy array from an array of strings.
For use in generating dates from strings for use with interp. Assumes the
array is either 0-dimensional or 1-dimensional.
Parameters
----------
strings : array of strings
Strings ... | [
"Create",
"a",
"numpy",
"array",
"from",
"an",
"array",
"of",
"strings",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftimeindex.py#L485-L503 | [
"def",
"_parse_array_of_cftime_strings",
"(",
"strings",
",",
"date_type",
")",
":",
"return",
"np",
".",
"array",
"(",
"[",
"_parse_iso8601_without_reso",
"(",
"date_type",
",",
"s",
")",
"for",
"s",
"in",
"strings",
".",
"ravel",
"(",
")",
"]",
")",
".",... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | CFTimeIndex._partial_date_slice | Adapted from
pandas.tseries.index.DatetimeIndex._partial_date_slice
Note that when using a CFTimeIndex, if a partial-date selection
returns a single element, it will never be converted to a scalar
coordinate; this is in slight contrast to the behavior when using
a DatetimeIndex,... | xarray/coding/cftimeindex.py | def _partial_date_slice(self, resolution, parsed):
"""Adapted from
pandas.tseries.index.DatetimeIndex._partial_date_slice
Note that when using a CFTimeIndex, if a partial-date selection
returns a single element, it will never be converted to a scalar
coordinate; this is in sligh... | def _partial_date_slice(self, resolution, parsed):
"""Adapted from
pandas.tseries.index.DatetimeIndex._partial_date_slice
Note that when using a CFTimeIndex, if a partial-date selection
returns a single element, it will never be converted to a scalar
coordinate; this is in sligh... | [
"Adapted",
"from",
"pandas",
".",
"tseries",
".",
"index",
".",
"DatetimeIndex",
".",
"_partial_date_slice"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftimeindex.py#L241-L301 | [
"def",
"_partial_date_slice",
"(",
"self",
",",
"resolution",
",",
"parsed",
")",
":",
"start",
",",
"end",
"=",
"_parsed_string_to_bounds",
"(",
"self",
".",
"date_type",
",",
"resolution",
",",
"parsed",
")",
"times",
"=",
"self",
".",
"_data",
"if",
"se... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | CFTimeIndex._get_string_slice | Adapted from pandas.tseries.index.DatetimeIndex._get_string_slice | xarray/coding/cftimeindex.py | def _get_string_slice(self, key):
"""Adapted from pandas.tseries.index.DatetimeIndex._get_string_slice"""
parsed, resolution = _parse_iso8601_with_reso(self.date_type, key)
try:
loc = self._partial_date_slice(resolution, parsed)
except KeyError:
raise KeyError(key... | def _get_string_slice(self, key):
"""Adapted from pandas.tseries.index.DatetimeIndex._get_string_slice"""
parsed, resolution = _parse_iso8601_with_reso(self.date_type, key)
try:
loc = self._partial_date_slice(resolution, parsed)
except KeyError:
raise KeyError(key... | [
"Adapted",
"from",
"pandas",
".",
"tseries",
".",
"index",
".",
"DatetimeIndex",
".",
"_get_string_slice"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftimeindex.py#L303-L310 | [
"def",
"_get_string_slice",
"(",
"self",
",",
"key",
")",
":",
"parsed",
",",
"resolution",
"=",
"_parse_iso8601_with_reso",
"(",
"self",
".",
"date_type",
",",
"key",
")",
"try",
":",
"loc",
"=",
"self",
".",
"_partial_date_slice",
"(",
"resolution",
",",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | CFTimeIndex.get_loc | Adapted from pandas.tseries.index.DatetimeIndex.get_loc | xarray/coding/cftimeindex.py | def get_loc(self, key, method=None, tolerance=None):
"""Adapted from pandas.tseries.index.DatetimeIndex.get_loc"""
if isinstance(key, str):
return self._get_string_slice(key)
else:
return pd.Index.get_loc(self, key, method=method,
toler... | def get_loc(self, key, method=None, tolerance=None):
"""Adapted from pandas.tseries.index.DatetimeIndex.get_loc"""
if isinstance(key, str):
return self._get_string_slice(key)
else:
return pd.Index.get_loc(self, key, method=method,
toler... | [
"Adapted",
"from",
"pandas",
".",
"tseries",
".",
"index",
".",
"DatetimeIndex",
".",
"get_loc"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftimeindex.py#L312-L318 | [
"def",
"get_loc",
"(",
"self",
",",
"key",
",",
"method",
"=",
"None",
",",
"tolerance",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"str",
")",
":",
"return",
"self",
".",
"_get_string_slice",
"(",
"key",
")",
"else",
":",
"return",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | CFTimeIndex._maybe_cast_slice_bound | Adapted from
pandas.tseries.index.DatetimeIndex._maybe_cast_slice_bound | xarray/coding/cftimeindex.py | def _maybe_cast_slice_bound(self, label, side, kind):
"""Adapted from
pandas.tseries.index.DatetimeIndex._maybe_cast_slice_bound"""
if isinstance(label, str):
parsed, resolution = _parse_iso8601_with_reso(self.date_type,
label... | def _maybe_cast_slice_bound(self, label, side, kind):
"""Adapted from
pandas.tseries.index.DatetimeIndex._maybe_cast_slice_bound"""
if isinstance(label, str):
parsed, resolution = _parse_iso8601_with_reso(self.date_type,
label... | [
"Adapted",
"from",
"pandas",
".",
"tseries",
".",
"index",
".",
"DatetimeIndex",
".",
"_maybe_cast_slice_bound"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftimeindex.py#L320-L332 | [
"def",
"_maybe_cast_slice_bound",
"(",
"self",
",",
"label",
",",
"side",
",",
"kind",
")",
":",
"if",
"isinstance",
"(",
"label",
",",
"str",
")",
":",
"parsed",
",",
"resolution",
"=",
"_parse_iso8601_with_reso",
"(",
"self",
".",
"date_type",
",",
"labe... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | CFTimeIndex.get_value | Adapted from pandas.tseries.index.DatetimeIndex.get_value | xarray/coding/cftimeindex.py | def get_value(self, series, key):
"""Adapted from pandas.tseries.index.DatetimeIndex.get_value"""
if np.asarray(key).dtype == np.dtype(bool):
return series.iloc[key]
elif isinstance(key, slice):
return series.iloc[self.slice_indexer(
key.start, key.stop, k... | def get_value(self, series, key):
"""Adapted from pandas.tseries.index.DatetimeIndex.get_value"""
if np.asarray(key).dtype == np.dtype(bool):
return series.iloc[key]
elif isinstance(key, slice):
return series.iloc[self.slice_indexer(
key.start, key.stop, k... | [
"Adapted",
"from",
"pandas",
".",
"tseries",
".",
"index",
".",
"DatetimeIndex",
".",
"get_value"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftimeindex.py#L336-L344 | [
"def",
"get_value",
"(",
"self",
",",
"series",
",",
"key",
")",
":",
"if",
"np",
".",
"asarray",
"(",
"key",
")",
".",
"dtype",
"==",
"np",
".",
"dtype",
"(",
"bool",
")",
":",
"return",
"series",
".",
"iloc",
"[",
"key",
"]",
"elif",
"isinstanc... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | CFTimeIndex.shift | Shift the CFTimeIndex a multiple of the given frequency.
See the documentation for :py:func:`~xarray.cftime_range` for a
complete listing of valid frequency strings.
Parameters
----------
n : int
Periods to shift by
freq : str or datetime.timedelta
... | xarray/coding/cftimeindex.py | def shift(self, n, freq):
"""Shift the CFTimeIndex a multiple of the given frequency.
See the documentation for :py:func:`~xarray.cftime_range` for a
complete listing of valid frequency strings.
Parameters
----------
n : int
Periods to shift by
freq ... | def shift(self, n, freq):
"""Shift the CFTimeIndex a multiple of the given frequency.
See the documentation for :py:func:`~xarray.cftime_range` for a
complete listing of valid frequency strings.
Parameters
----------
n : int
Periods to shift by
freq ... | [
"Shift",
"the",
"CFTimeIndex",
"a",
"multiple",
"of",
"the",
"given",
"frequency",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftimeindex.py#L360-L400 | [
"def",
"shift",
"(",
"self",
",",
"n",
",",
"freq",
")",
":",
"from",
".",
"cftime_offsets",
"import",
"to_offset",
"if",
"not",
"isinstance",
"(",
"n",
",",
"int",
")",
":",
"raise",
"TypeError",
"(",
"\"'n' must be an int, got {}.\"",
".",
"format",
"(",... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | CFTimeIndex.to_datetimeindex | If possible, convert this index to a pandas.DatetimeIndex.
Parameters
----------
unsafe : bool
Flag to turn off warning when converting from a CFTimeIndex with
a non-standard calendar to a DatetimeIndex (default ``False``).
Returns
-------
pandas... | xarray/coding/cftimeindex.py | def to_datetimeindex(self, unsafe=False):
"""If possible, convert this index to a pandas.DatetimeIndex.
Parameters
----------
unsafe : bool
Flag to turn off warning when converting from a CFTimeIndex with
a non-standard calendar to a DatetimeIndex (default ``Fals... | def to_datetimeindex(self, unsafe=False):
"""If possible, convert this index to a pandas.DatetimeIndex.
Parameters
----------
unsafe : bool
Flag to turn off warning when converting from a CFTimeIndex with
a non-standard calendar to a DatetimeIndex (default ``Fals... | [
"If",
"possible",
"convert",
"this",
"index",
"to",
"a",
"pandas",
".",
"DatetimeIndex",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftimeindex.py#L429-L477 | [
"def",
"to_datetimeindex",
"(",
"self",
",",
"unsafe",
"=",
"False",
")",
":",
"# noqa: E501",
"nptimes",
"=",
"cftime_to_nptime",
"(",
"self",
")",
"calendar",
"=",
"infer_calendar_name",
"(",
"self",
")",
"if",
"calendar",
"not",
"in",
"_STANDARD_CALENDARS",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _dask_or_eager_func | Create a function that dispatches to dask for dask array inputs. | xarray/core/duck_array_ops.py | def _dask_or_eager_func(name, eager_module=np, dask_module=dask_array,
list_of_args=False, array_args=slice(1),
requires_dask=None):
"""Create a function that dispatches to dask for dask array inputs."""
if dask_module is not None:
def f(*args, **kwargs):
... | def _dask_or_eager_func(name, eager_module=np, dask_module=dask_array,
list_of_args=False, array_args=slice(1),
requires_dask=None):
"""Create a function that dispatches to dask for dask array inputs."""
if dask_module is not None:
def f(*args, **kwargs):
... | [
"Create",
"a",
"function",
"that",
"dispatches",
"to",
"dask",
"for",
"dask",
"array",
"inputs",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/duck_array_ops.py#L26-L48 | [
"def",
"_dask_or_eager_func",
"(",
"name",
",",
"eager_module",
"=",
"np",
",",
"dask_module",
"=",
"dask_array",
",",
"list_of_args",
"=",
"False",
",",
"array_args",
"=",
"slice",
"(",
"1",
")",
",",
"requires_dask",
"=",
"None",
")",
":",
"if",
"dask_mo... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | as_shared_dtype | Cast a arrays to a shared dtype using xarray's type promotion rules. | xarray/core/duck_array_ops.py | def as_shared_dtype(scalars_or_arrays):
"""Cast a arrays to a shared dtype using xarray's type promotion rules."""
arrays = [asarray(x) for x in scalars_or_arrays]
# Pass arrays directly instead of dtypes to result_type so scalars
# get handled properly.
# Note that result_type() safely gets the dty... | def as_shared_dtype(scalars_or_arrays):
"""Cast a arrays to a shared dtype using xarray's type promotion rules."""
arrays = [asarray(x) for x in scalars_or_arrays]
# Pass arrays directly instead of dtypes to result_type so scalars
# get handled properly.
# Note that result_type() safely gets the dty... | [
"Cast",
"a",
"arrays",
"to",
"a",
"shared",
"dtype",
"using",
"xarray",
"s",
"type",
"promotion",
"rules",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/duck_array_ops.py#L123-L131 | [
"def",
"as_shared_dtype",
"(",
"scalars_or_arrays",
")",
":",
"arrays",
"=",
"[",
"asarray",
"(",
"x",
")",
"for",
"x",
"in",
"scalars_or_arrays",
"]",
"# Pass arrays directly instead of dtypes to result_type so scalars",
"# get handled properly.",
"# Note that result_type() ... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | allclose_or_equiv | Like np.allclose, but also allows values to be NaN in both arrays | xarray/core/duck_array_ops.py | def allclose_or_equiv(arr1, arr2, rtol=1e-5, atol=1e-8):
"""Like np.allclose, but also allows values to be NaN in both arrays
"""
arr1, arr2 = as_like_arrays(arr1, arr2)
if arr1.shape != arr2.shape:
return False
return bool(
isclose(arr1, arr2, rtol=rtol, atol=atol, equal_nan=True).a... | def allclose_or_equiv(arr1, arr2, rtol=1e-5, atol=1e-8):
"""Like np.allclose, but also allows values to be NaN in both arrays
"""
arr1, arr2 = as_like_arrays(arr1, arr2)
if arr1.shape != arr2.shape:
return False
return bool(
isclose(arr1, arr2, rtol=rtol, atol=atol, equal_nan=True).a... | [
"Like",
"np",
".",
"allclose",
"but",
"also",
"allows",
"values",
"to",
"be",
"NaN",
"in",
"both",
"arrays"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/duck_array_ops.py#L141-L148 | [
"def",
"allclose_or_equiv",
"(",
"arr1",
",",
"arr2",
",",
"rtol",
"=",
"1e-5",
",",
"atol",
"=",
"1e-8",
")",
":",
"arr1",
",",
"arr2",
"=",
"as_like_arrays",
"(",
"arr1",
",",
"arr2",
")",
"if",
"arr1",
".",
"shape",
"!=",
"arr2",
".",
"shape",
"... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | array_equiv | Like np.array_equal, but also allows values to be NaN in both arrays | xarray/core/duck_array_ops.py | def array_equiv(arr1, arr2):
"""Like np.array_equal, but also allows values to be NaN in both arrays
"""
arr1, arr2 = as_like_arrays(arr1, arr2)
if arr1.shape != arr2.shape:
return False
with warnings.catch_warnings():
warnings.filterwarnings('ignore', "In the future, 'NAT == x'")
... | def array_equiv(arr1, arr2):
"""Like np.array_equal, but also allows values to be NaN in both arrays
"""
arr1, arr2 = as_like_arrays(arr1, arr2)
if arr1.shape != arr2.shape:
return False
with warnings.catch_warnings():
warnings.filterwarnings('ignore', "In the future, 'NAT == x'")
... | [
"Like",
"np",
".",
"array_equal",
"but",
"also",
"allows",
"values",
"to",
"be",
"NaN",
"in",
"both",
"arrays"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/duck_array_ops.py#L151-L164 | [
"def",
"array_equiv",
"(",
"arr1",
",",
"arr2",
")",
":",
"arr1",
",",
"arr2",
"=",
"as_like_arrays",
"(",
"arr1",
",",
"arr2",
")",
"if",
"arr1",
".",
"shape",
"!=",
"arr2",
".",
"shape",
":",
"return",
"False",
"with",
"warnings",
".",
"catch_warning... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | count | Count the number of non-NA in this array along the given axis or axes | xarray/core/duck_array_ops.py | def count(data, axis=None):
"""Count the number of non-NA in this array along the given axis or axes
"""
return np.sum(np.logical_not(isnull(data)), axis=axis) | def count(data, axis=None):
"""Count the number of non-NA in this array along the given axis or axes
"""
return np.sum(np.logical_not(isnull(data)), axis=axis) | [
"Count",
"the",
"number",
"of",
"non",
"-",
"NA",
"in",
"this",
"array",
"along",
"the",
"given",
"axis",
"or",
"axes"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/duck_array_ops.py#L185-L188 | [
"def",
"count",
"(",
"data",
",",
"axis",
"=",
"None",
")",
":",
"return",
"np",
".",
"sum",
"(",
"np",
".",
"logical_not",
"(",
"isnull",
"(",
"data",
")",
")",
",",
"axis",
"=",
"axis",
")"
] | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | datetime_to_numeric | Convert an array containing datetime-like data to an array of floats.
Parameters
----------
da : np.array
Input data
offset: Scalar with the same type of array or None
If None, subtract minimum values to reduce round off error
datetime_unit: None or any of {'Y', 'M', 'W', 'D', 'h', ... | xarray/core/duck_array_ops.py | def datetime_to_numeric(array, offset=None, datetime_unit=None, dtype=float):
"""Convert an array containing datetime-like data to an array of floats.
Parameters
----------
da : np.array
Input data
offset: Scalar with the same type of array or None
If None, subtract minimum values t... | def datetime_to_numeric(array, offset=None, datetime_unit=None, dtype=float):
"""Convert an array containing datetime-like data to an array of floats.
Parameters
----------
da : np.array
Input data
offset: Scalar with the same type of array or None
If None, subtract minimum values t... | [
"Convert",
"an",
"array",
"containing",
"datetime",
"-",
"like",
"data",
"to",
"an",
"array",
"of",
"floats",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/duck_array_ops.py#L292-L327 | [
"def",
"datetime_to_numeric",
"(",
"array",
",",
"offset",
"=",
"None",
",",
"datetime_unit",
"=",
"None",
",",
"dtype",
"=",
"float",
")",
":",
"# TODO: make this function dask-compatible?",
"if",
"offset",
"is",
"None",
":",
"offset",
"=",
"array",
".",
"min... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | mean | inhouse mean that can handle np.datetime64 or cftime.datetime
dtypes | xarray/core/duck_array_ops.py | def mean(array, axis=None, skipna=None, **kwargs):
"""inhouse mean that can handle np.datetime64 or cftime.datetime
dtypes"""
from .common import _contains_cftime_datetimes
array = asarray(array)
if array.dtype.kind in 'Mm':
offset = min(array)
# xarray always uses np.datetime64[ns]... | def mean(array, axis=None, skipna=None, **kwargs):
"""inhouse mean that can handle np.datetime64 or cftime.datetime
dtypes"""
from .common import _contains_cftime_datetimes
array = asarray(array)
if array.dtype.kind in 'Mm':
offset = min(array)
# xarray always uses np.datetime64[ns]... | [
"inhouse",
"mean",
"that",
"can",
"handle",
"np",
".",
"datetime64",
"or",
"cftime",
".",
"datetime",
"dtypes"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/duck_array_ops.py#L335-L359 | [
"def",
"mean",
"(",
"array",
",",
"axis",
"=",
"None",
",",
"skipna",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
".",
"common",
"import",
"_contains_cftime_datetimes",
"array",
"=",
"asarray",
"(",
"array",
")",
"if",
"array",
".",
"dtype"... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | first | Return the first non-NA elements in this array along the given axis | xarray/core/duck_array_ops.py | def first(values, axis, skipna=None):
"""Return the first non-NA elements in this array along the given axis
"""
if (skipna or skipna is None) and values.dtype.kind not in 'iSU':
# only bother for dtypes that can hold NaN
_fail_on_dask_array_input_skipna(values)
return nanfirst(value... | def first(values, axis, skipna=None):
"""Return the first non-NA elements in this array along the given axis
"""
if (skipna or skipna is None) and values.dtype.kind not in 'iSU':
# only bother for dtypes that can hold NaN
_fail_on_dask_array_input_skipna(values)
return nanfirst(value... | [
"Return",
"the",
"first",
"non",
"-",
"NA",
"elements",
"in",
"this",
"array",
"along",
"the",
"given",
"axis"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/duck_array_ops.py#L393-L400 | [
"def",
"first",
"(",
"values",
",",
"axis",
",",
"skipna",
"=",
"None",
")",
":",
"if",
"(",
"skipna",
"or",
"skipna",
"is",
"None",
")",
"and",
"values",
".",
"dtype",
".",
"kind",
"not",
"in",
"'iSU'",
":",
"# only bother for dtypes that can hold NaN",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | last | Return the last non-NA elements in this array along the given axis | xarray/core/duck_array_ops.py | def last(values, axis, skipna=None):
"""Return the last non-NA elements in this array along the given axis
"""
if (skipna or skipna is None) and values.dtype.kind not in 'iSU':
# only bother for dtypes that can hold NaN
_fail_on_dask_array_input_skipna(values)
return nanlast(values, ... | def last(values, axis, skipna=None):
"""Return the last non-NA elements in this array along the given axis
"""
if (skipna or skipna is None) and values.dtype.kind not in 'iSU':
# only bother for dtypes that can hold NaN
_fail_on_dask_array_input_skipna(values)
return nanlast(values, ... | [
"Return",
"the",
"last",
"non",
"-",
"NA",
"elements",
"in",
"this",
"array",
"along",
"the",
"given",
"axis"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/duck_array_ops.py#L403-L410 | [
"def",
"last",
"(",
"values",
",",
"axis",
",",
"skipna",
"=",
"None",
")",
":",
"if",
"(",
"skipna",
"or",
"skipna",
"is",
"None",
")",
"and",
"values",
".",
"dtype",
".",
"kind",
"not",
"in",
"'iSU'",
":",
"# only bother for dtypes that can hold NaN",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | rolling_window | Make an ndarray with a rolling window of axis-th dimension.
The rolling dimension will be placed at the last dimension. | xarray/core/duck_array_ops.py | def rolling_window(array, axis, window, center, fill_value):
"""
Make an ndarray with a rolling window of axis-th dimension.
The rolling dimension will be placed at the last dimension.
"""
if isinstance(array, dask_array_type):
return dask_array_ops.rolling_window(
array, axis, w... | def rolling_window(array, axis, window, center, fill_value):
"""
Make an ndarray with a rolling window of axis-th dimension.
The rolling dimension will be placed at the last dimension.
"""
if isinstance(array, dask_array_type):
return dask_array_ops.rolling_window(
array, axis, w... | [
"Make",
"an",
"ndarray",
"with",
"a",
"rolling",
"window",
"of",
"axis",
"-",
"th",
"dimension",
".",
"The",
"rolling",
"dimension",
"will",
"be",
"placed",
"at",
"the",
"last",
"dimension",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/duck_array_ops.py#L413-L423 | [
"def",
"rolling_window",
"(",
"array",
",",
"axis",
",",
"window",
",",
"center",
",",
"fill_value",
")",
":",
"if",
"isinstance",
"(",
"array",
",",
"dask_array_type",
")",
":",
"return",
"dask_array_ops",
".",
"rolling_window",
"(",
"array",
",",
"axis",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | concat | Concatenate xarray objects along a new or existing dimension.
Parameters
----------
objs : sequence of Dataset and DataArray objects
xarray objects to concatenate together. Each object is expected to
consist of variables and coordinates with matching shapes except for
along the conc... | xarray/core/combine.py | def concat(objs, dim=None, data_vars='all', coords='different',
compat='equals', positions=None, indexers=None, mode=None,
concat_over=None):
"""Concatenate xarray objects along a new or existing dimension.
Parameters
----------
objs : sequence of Dataset and DataArray objects
... | def concat(objs, dim=None, data_vars='all', coords='different',
compat='equals', positions=None, indexers=None, mode=None,
concat_over=None):
"""Concatenate xarray objects along a new or existing dimension.
Parameters
----------
objs : sequence of Dataset and DataArray objects
... | [
"Concatenate",
"xarray",
"objects",
"along",
"a",
"new",
"or",
"existing",
"dimension",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/combine.py#L15-L120 | [
"def",
"concat",
"(",
"objs",
",",
"dim",
"=",
"None",
",",
"data_vars",
"=",
"'all'",
",",
"coords",
"=",
"'different'",
",",
"compat",
"=",
"'equals'",
",",
"positions",
"=",
"None",
",",
"indexers",
"=",
"None",
",",
"mode",
"=",
"None",
",",
"con... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _calc_concat_dim_coord | Infer the dimension name and 1d coordinate variable (if appropriate)
for concatenating along the new dimension. | xarray/core/combine.py | def _calc_concat_dim_coord(dim):
"""
Infer the dimension name and 1d coordinate variable (if appropriate)
for concatenating along the new dimension.
"""
from .dataarray import DataArray
if isinstance(dim, str):
coord = None
elif not isinstance(dim, (DataArray, Variable)):
di... | def _calc_concat_dim_coord(dim):
"""
Infer the dimension name and 1d coordinate variable (if appropriate)
for concatenating along the new dimension.
"""
from .dataarray import DataArray
if isinstance(dim, str):
coord = None
elif not isinstance(dim, (DataArray, Variable)):
di... | [
"Infer",
"the",
"dimension",
"name",
"and",
"1d",
"coordinate",
"variable",
"(",
"if",
"appropriate",
")",
"for",
"concatenating",
"along",
"the",
"new",
"dimension",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/combine.py#L123-L144 | [
"def",
"_calc_concat_dim_coord",
"(",
"dim",
")",
":",
"from",
".",
"dataarray",
"import",
"DataArray",
"if",
"isinstance",
"(",
"dim",
",",
"str",
")",
":",
"coord",
"=",
"None",
"elif",
"not",
"isinstance",
"(",
"dim",
",",
"(",
"DataArray",
",",
"Vari... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _calc_concat_over | Determine which dataset variables need to be concatenated in the result,
and which can simply be taken from the first dataset. | xarray/core/combine.py | def _calc_concat_over(datasets, dim, data_vars, coords):
"""
Determine which dataset variables need to be concatenated in the result,
and which can simply be taken from the first dataset.
"""
# Return values
concat_over = set()
equals = {}
if dim in datasets[0]:
concat_over.add(... | def _calc_concat_over(datasets, dim, data_vars, coords):
"""
Determine which dataset variables need to be concatenated in the result,
and which can simply be taken from the first dataset.
"""
# Return values
concat_over = set()
equals = {}
if dim in datasets[0]:
concat_over.add(... | [
"Determine",
"which",
"dataset",
"variables",
"need",
"to",
"be",
"concatenated",
"in",
"the",
"result",
"and",
"which",
"can",
"simply",
"be",
"taken",
"from",
"the",
"first",
"dataset",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/combine.py#L147-L212 | [
"def",
"_calc_concat_over",
"(",
"datasets",
",",
"dim",
",",
"data_vars",
",",
"coords",
")",
":",
"# Return values",
"concat_over",
"=",
"set",
"(",
")",
"equals",
"=",
"{",
"}",
"if",
"dim",
"in",
"datasets",
"[",
"0",
"]",
":",
"concat_over",
".",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _dataset_concat | Concatenate a sequence of datasets along a new or existing dimension | xarray/core/combine.py | def _dataset_concat(datasets, dim, data_vars, coords, compat, positions):
"""
Concatenate a sequence of datasets along a new or existing dimension
"""
from .dataset import Dataset
if compat not in ['equals', 'identical']:
raise ValueError("compat=%r invalid: must be 'equals' "
... | def _dataset_concat(datasets, dim, data_vars, coords, compat, positions):
"""
Concatenate a sequence of datasets along a new or existing dimension
"""
from .dataset import Dataset
if compat not in ['equals', 'identical']:
raise ValueError("compat=%r invalid: must be 'equals' "
... | [
"Concatenate",
"a",
"sequence",
"of",
"datasets",
"along",
"a",
"new",
"or",
"existing",
"dimension"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/combine.py#L215-L316 | [
"def",
"_dataset_concat",
"(",
"datasets",
",",
"dim",
",",
"data_vars",
",",
"coords",
",",
"compat",
",",
"positions",
")",
":",
"from",
".",
"dataset",
"import",
"Dataset",
"if",
"compat",
"not",
"in",
"[",
"'equals'",
",",
"'identical'",
"]",
":",
"r... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _infer_tile_ids_from_nested_list | Given a list of lists (of lists...) of objects, returns a iterator
which returns a tuple containing the index of each object in the nested
list structure as the key, and the object. This can then be called by the
dict constructor to create a dictionary of the objects organised by their
position in the o... | xarray/core/combine.py | def _infer_tile_ids_from_nested_list(entry, current_pos):
"""
Given a list of lists (of lists...) of objects, returns a iterator
which returns a tuple containing the index of each object in the nested
list structure as the key, and the object. This can then be called by the
dict constructor to creat... | def _infer_tile_ids_from_nested_list(entry, current_pos):
"""
Given a list of lists (of lists...) of objects, returns a iterator
which returns a tuple containing the index of each object in the nested
list structure as the key, and the object. This can then be called by the
dict constructor to creat... | [
"Given",
"a",
"list",
"of",
"lists",
"(",
"of",
"lists",
"...",
")",
"of",
"objects",
"returns",
"a",
"iterator",
"which",
"returns",
"a",
"tuple",
"containing",
"the",
"index",
"of",
"each",
"object",
"in",
"the",
"nested",
"list",
"structure",
"as",
"t... | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/combine.py#L393-L421 | [
"def",
"_infer_tile_ids_from_nested_list",
"(",
"entry",
",",
"current_pos",
")",
":",
"if",
"isinstance",
"(",
"entry",
",",
"list",
")",
":",
"for",
"i",
",",
"item",
"in",
"enumerate",
"(",
"entry",
")",
":",
"for",
"result",
"in",
"_infer_tile_ids_from_n... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _combine_nd | Concatenates and merges an N-dimensional structure of datasets.
No checks are performed on the consistency of the datasets, concat_dims or
tile_IDs, because it is assumed that this has already been done.
Parameters
----------
combined_ids : Dict[Tuple[int, ...]], xarray.Dataset]
Structure ... | xarray/core/combine.py | def _combine_nd(combined_ids, concat_dims, data_vars='all',
coords='different', compat='no_conflicts'):
"""
Concatenates and merges an N-dimensional structure of datasets.
No checks are performed on the consistency of the datasets, concat_dims or
tile_IDs, because it is assumed that thi... | def _combine_nd(combined_ids, concat_dims, data_vars='all',
coords='different', compat='no_conflicts'):
"""
Concatenates and merges an N-dimensional structure of datasets.
No checks are performed on the consistency of the datasets, concat_dims or
tile_IDs, because it is assumed that thi... | [
"Concatenates",
"and",
"merges",
"an",
"N",
"-",
"dimensional",
"structure",
"of",
"datasets",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/combine.py#L444-L477 | [
"def",
"_combine_nd",
"(",
"combined_ids",
",",
"concat_dims",
",",
"data_vars",
"=",
"'all'",
",",
"coords",
"=",
"'different'",
",",
"compat",
"=",
"'no_conflicts'",
")",
":",
"# Perform N-D dimensional concatenation",
"# Each iteration of this loop reduces the length of ... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _auto_combine | Calls logic to decide concatenation order before concatenating. | xarray/core/combine.py | def _auto_combine(datasets, concat_dims, compat, data_vars, coords,
infer_order_from_coords, ids):
"""
Calls logic to decide concatenation order before concatenating.
"""
# Arrange datasets for concatenation
if infer_order_from_coords:
raise NotImplementedError
# T... | def _auto_combine(datasets, concat_dims, compat, data_vars, coords,
infer_order_from_coords, ids):
"""
Calls logic to decide concatenation order before concatenating.
"""
# Arrange datasets for concatenation
if infer_order_from_coords:
raise NotImplementedError
# T... | [
"Calls",
"logic",
"to",
"decide",
"concatenation",
"order",
"before",
"concatenating",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/combine.py#L523-L554 | [
"def",
"_auto_combine",
"(",
"datasets",
",",
"concat_dims",
",",
"compat",
",",
"data_vars",
",",
"coords",
",",
"infer_order_from_coords",
",",
"ids",
")",
":",
"# Arrange datasets for concatenation",
"if",
"infer_order_from_coords",
":",
"raise",
"NotImplementedError... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | auto_combine | Attempt to auto-magically combine the given datasets into one.
This method attempts to combine a list of datasets into a single entity by
inspecting metadata and using a combination of concat and merge.
It does not concatenate along more than one dimension or sort data under
any circumstances. It does a... | xarray/core/combine.py | def auto_combine(datasets, concat_dim=_CONCAT_DIM_DEFAULT,
compat='no_conflicts', data_vars='all', coords='different'):
"""Attempt to auto-magically combine the given datasets into one.
This method attempts to combine a list of datasets into a single entity by
inspecting metadata and using ... | def auto_combine(datasets, concat_dim=_CONCAT_DIM_DEFAULT,
compat='no_conflicts', data_vars='all', coords='different'):
"""Attempt to auto-magically combine the given datasets into one.
This method attempts to combine a list of datasets into a single entity by
inspecting metadata and using ... | [
"Attempt",
"to",
"auto",
"-",
"magically",
"combine",
"the",
"given",
"datasets",
"into",
"one",
".",
"This",
"method",
"attempts",
"to",
"combine",
"a",
"list",
"of",
"datasets",
"into",
"a",
"single",
"entity",
"by",
"inspecting",
"metadata",
"and",
"using... | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/combine.py#L557-L625 | [
"def",
"auto_combine",
"(",
"datasets",
",",
"concat_dim",
"=",
"_CONCAT_DIM_DEFAULT",
",",
"compat",
"=",
"'no_conflicts'",
",",
"data_vars",
"=",
"'all'",
",",
"coords",
"=",
"'different'",
")",
":",
"# noqa",
"# Coerce 1D input into ND to maintain backwards-compatibl... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | get_date_type | Return the cftime date type for a given calendar name. | xarray/coding/cftime_offsets.py | def get_date_type(calendar):
"""Return the cftime date type for a given calendar name."""
try:
import cftime
except ImportError:
raise ImportError(
'cftime is required for dates with non-standard calendars')
else:
calendars = {
'noleap': cftime.DatetimeNoL... | def get_date_type(calendar):
"""Return the cftime date type for a given calendar name."""
try:
import cftime
except ImportError:
raise ImportError(
'cftime is required for dates with non-standard calendars')
else:
calendars = {
'noleap': cftime.DatetimeNoL... | [
"Return",
"the",
"cftime",
"date",
"type",
"for",
"a",
"given",
"calendar",
"name",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L58-L77 | [
"def",
"get_date_type",
"(",
"calendar",
")",
":",
"try",
":",
"import",
"cftime",
"except",
"ImportError",
":",
"raise",
"ImportError",
"(",
"'cftime is required for dates with non-standard calendars'",
")",
"else",
":",
"calendars",
"=",
"{",
"'noleap'",
":",
"cft... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _get_day_of_month | Find the day in `other`'s month that satisfies a BaseCFTimeOffset's
onOffset policy, as described by the `day_option` argument.
Parameters
----------
other : cftime.datetime
day_option : 'start', 'end'
'start': returns 1
'end': returns last day of the month
Returns
-------
... | xarray/coding/cftime_offsets.py | def _get_day_of_month(other, day_option):
"""Find the day in `other`'s month that satisfies a BaseCFTimeOffset's
onOffset policy, as described by the `day_option` argument.
Parameters
----------
other : cftime.datetime
day_option : 'start', 'end'
'start': returns 1
'end': return... | def _get_day_of_month(other, day_option):
"""Find the day in `other`'s month that satisfies a BaseCFTimeOffset's
onOffset policy, as described by the `day_option` argument.
Parameters
----------
other : cftime.datetime
day_option : 'start', 'end'
'start': returns 1
'end': return... | [
"Find",
"the",
"day",
"in",
"other",
"s",
"month",
"that",
"satisfies",
"a",
"BaseCFTimeOffset",
"s",
"onOffset",
"policy",
"as",
"described",
"by",
"the",
"day_option",
"argument",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L165-L192 | [
"def",
"_get_day_of_month",
"(",
"other",
",",
"day_option",
")",
":",
"if",
"day_option",
"==",
"'start'",
":",
"return",
"1",
"elif",
"day_option",
"==",
"'end'",
":",
"days_in_month",
"=",
"_days_in_month",
"(",
"other",
")",
"return",
"days_in_month",
"eli... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _days_in_month | The number of days in the month of the given date | xarray/coding/cftime_offsets.py | def _days_in_month(date):
"""The number of days in the month of the given date"""
if date.month == 12:
reference = type(date)(date.year + 1, 1, 1)
else:
reference = type(date)(date.year, date.month + 1, 1)
return (reference - timedelta(days=1)).day | def _days_in_month(date):
"""The number of days in the month of the given date"""
if date.month == 12:
reference = type(date)(date.year + 1, 1, 1)
else:
reference = type(date)(date.year, date.month + 1, 1)
return (reference - timedelta(days=1)).day | [
"The",
"number",
"of",
"days",
"in",
"the",
"month",
"of",
"the",
"given",
"date"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L195-L201 | [
"def",
"_days_in_month",
"(",
"date",
")",
":",
"if",
"date",
".",
"month",
"==",
"12",
":",
"reference",
"=",
"type",
"(",
"date",
")",
"(",
"date",
".",
"year",
"+",
"1",
",",
"1",
",",
"1",
")",
"else",
":",
"reference",
"=",
"type",
"(",
"d... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _adjust_n_months | Adjust the number of times a monthly offset is applied based
on the day of a given date, and the reference day provided. | xarray/coding/cftime_offsets.py | def _adjust_n_months(other_day, n, reference_day):
"""Adjust the number of times a monthly offset is applied based
on the day of a given date, and the reference day provided.
"""
if n > 0 and other_day < reference_day:
n = n - 1
elif n <= 0 and other_day > reference_day:
n = n + 1
... | def _adjust_n_months(other_day, n, reference_day):
"""Adjust the number of times a monthly offset is applied based
on the day of a given date, and the reference day provided.
"""
if n > 0 and other_day < reference_day:
n = n - 1
elif n <= 0 and other_day > reference_day:
n = n + 1
... | [
"Adjust",
"the",
"number",
"of",
"times",
"a",
"monthly",
"offset",
"is",
"applied",
"based",
"on",
"the",
"day",
"of",
"a",
"given",
"date",
"and",
"the",
"reference",
"day",
"provided",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L204-L212 | [
"def",
"_adjust_n_months",
"(",
"other_day",
",",
"n",
",",
"reference_day",
")",
":",
"if",
"n",
">",
"0",
"and",
"other_day",
"<",
"reference_day",
":",
"n",
"=",
"n",
"-",
"1",
"elif",
"n",
"<=",
"0",
"and",
"other_day",
">",
"reference_day",
":",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _adjust_n_years | Adjust the number of times an annual offset is applied based on
another date, and the reference day provided | xarray/coding/cftime_offsets.py | def _adjust_n_years(other, n, month, reference_day):
"""Adjust the number of times an annual offset is applied based on
another date, and the reference day provided"""
if n > 0:
if other.month < month or (other.month == month and
other.day < reference_day):
... | def _adjust_n_years(other, n, month, reference_day):
"""Adjust the number of times an annual offset is applied based on
another date, and the reference day provided"""
if n > 0:
if other.month < month or (other.month == month and
other.day < reference_day):
... | [
"Adjust",
"the",
"number",
"of",
"times",
"an",
"annual",
"offset",
"is",
"applied",
"based",
"on",
"another",
"date",
"and",
"the",
"reference",
"day",
"provided"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L215-L226 | [
"def",
"_adjust_n_years",
"(",
"other",
",",
"n",
",",
"month",
",",
"reference_day",
")",
":",
"if",
"n",
">",
"0",
":",
"if",
"other",
".",
"month",
"<",
"month",
"or",
"(",
"other",
".",
"month",
"==",
"month",
"and",
"other",
".",
"day",
"<",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _shift_month | Shift the date to a month start or end a given number of months away. | xarray/coding/cftime_offsets.py | def _shift_month(date, months, day_option='start'):
"""Shift the date to a month start or end a given number of months away.
"""
delta_year = (date.month + months) // 12
month = (date.month + months) % 12
if month == 0:
month = 12
delta_year = delta_year - 1
year = date.year + d... | def _shift_month(date, months, day_option='start'):
"""Shift the date to a month start or end a given number of months away.
"""
delta_year = (date.month + months) // 12
month = (date.month + months) % 12
if month == 0:
month = 12
delta_year = delta_year - 1
year = date.year + d... | [
"Shift",
"the",
"date",
"to",
"a",
"month",
"start",
"or",
"end",
"a",
"given",
"number",
"of",
"months",
"away",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L229-L251 | [
"def",
"_shift_month",
"(",
"date",
",",
"months",
",",
"day_option",
"=",
"'start'",
")",
":",
"delta_year",
"=",
"(",
"date",
".",
"month",
"+",
"months",
")",
"//",
"12",
"month",
"=",
"(",
"date",
".",
"month",
"+",
"months",
")",
"%",
"12",
"i... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | roll_qtrday | Possibly increment or decrement the number of periods to shift
based on rollforward/rollbackward conventions.
Parameters
----------
other : cftime.datetime
n : number of periods to increment, before adjusting for rolling
month : int reference month giving the first month of the year
day_opt... | xarray/coding/cftime_offsets.py | def roll_qtrday(other, n, month, day_option, modby=3):
"""Possibly increment or decrement the number of periods to shift
based on rollforward/rollbackward conventions.
Parameters
----------
other : cftime.datetime
n : number of periods to increment, before adjusting for rolling
month : int ... | def roll_qtrday(other, n, month, day_option, modby=3):
"""Possibly increment or decrement the number of periods to shift
based on rollforward/rollbackward conventions.
Parameters
----------
other : cftime.datetime
n : number of periods to increment, before adjusting for rolling
month : int ... | [
"Possibly",
"increment",
"or",
"decrement",
"the",
"number",
"of",
"periods",
"to",
"shift",
"based",
"on",
"rollforward",
"/",
"rollbackward",
"conventions",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L254-L292 | [
"def",
"roll_qtrday",
"(",
"other",
",",
"n",
",",
"month",
",",
"day_option",
",",
"modby",
"=",
"3",
")",
":",
"months_since",
"=",
"other",
".",
"month",
"%",
"modby",
"-",
"month",
"%",
"modby",
"if",
"n",
">",
"0",
":",
"if",
"months_since",
"... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | to_offset | Convert a frequency string to the appropriate subclass of
BaseCFTimeOffset. | xarray/coding/cftime_offsets.py | def to_offset(freq):
"""Convert a frequency string to the appropriate subclass of
BaseCFTimeOffset."""
if isinstance(freq, BaseCFTimeOffset):
return freq
else:
try:
freq_data = re.match(_PATTERN, freq).groupdict()
except AttributeError:
raise ValueError('I... | def to_offset(freq):
"""Convert a frequency string to the appropriate subclass of
BaseCFTimeOffset."""
if isinstance(freq, BaseCFTimeOffset):
return freq
else:
try:
freq_data = re.match(_PATTERN, freq).groupdict()
except AttributeError:
raise ValueError('I... | [
"Convert",
"a",
"frequency",
"string",
"to",
"the",
"appropriate",
"subclass",
"of",
"BaseCFTimeOffset",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L653-L671 | [
"def",
"to_offset",
"(",
"freq",
")",
":",
"if",
"isinstance",
"(",
"freq",
",",
"BaseCFTimeOffset",
")",
":",
"return",
"freq",
"else",
":",
"try",
":",
"freq_data",
"=",
"re",
".",
"match",
"(",
"_PATTERN",
",",
"freq",
")",
".",
"groupdict",
"(",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _generate_linear_range | Generate an equally-spaced sequence of cftime.datetime objects between
and including two dates (whose length equals the number of periods). | xarray/coding/cftime_offsets.py | def _generate_linear_range(start, end, periods):
"""Generate an equally-spaced sequence of cftime.datetime objects between
and including two dates (whose length equals the number of periods)."""
import cftime
total_seconds = (end - start).total_seconds()
values = np.linspace(0., total_seconds, peri... | def _generate_linear_range(start, end, periods):
"""Generate an equally-spaced sequence of cftime.datetime objects between
and including two dates (whose length equals the number of periods)."""
import cftime
total_seconds = (end - start).total_seconds()
values = np.linspace(0., total_seconds, peri... | [
"Generate",
"an",
"equally",
"-",
"spaced",
"sequence",
"of",
"cftime",
".",
"datetime",
"objects",
"between",
"and",
"including",
"two",
"dates",
"(",
"whose",
"length",
"equals",
"the",
"number",
"of",
"periods",
")",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L706-L716 | [
"def",
"_generate_linear_range",
"(",
"start",
",",
"end",
",",
"periods",
")",
":",
"import",
"cftime",
"total_seconds",
"=",
"(",
"end",
"-",
"start",
")",
".",
"total_seconds",
"(",
")",
"values",
"=",
"np",
".",
"linspace",
"(",
"0.",
",",
"total_sec... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _generate_range | Generate a regular range of cftime.datetime objects with a
given time offset.
Adapted from pandas.tseries.offsets.generate_range.
Parameters
----------
start : cftime.datetime, or None
Start of range
end : cftime.datetime, or None
End of range
periods : int, or None
... | xarray/coding/cftime_offsets.py | def _generate_range(start, end, periods, offset):
"""Generate a regular range of cftime.datetime objects with a
given time offset.
Adapted from pandas.tseries.offsets.generate_range.
Parameters
----------
start : cftime.datetime, or None
Start of range
end : cftime.datetime, or Non... | def _generate_range(start, end, periods, offset):
"""Generate a regular range of cftime.datetime objects with a
given time offset.
Adapted from pandas.tseries.offsets.generate_range.
Parameters
----------
start : cftime.datetime, or None
Start of range
end : cftime.datetime, or Non... | [
"Generate",
"a",
"regular",
"range",
"of",
"cftime",
".",
"datetime",
"objects",
"with",
"a",
"given",
"time",
"offset",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L719-L774 | [
"def",
"_generate_range",
"(",
"start",
",",
"end",
",",
"periods",
",",
"offset",
")",
":",
"if",
"start",
":",
"start",
"=",
"offset",
".",
"rollforward",
"(",
"start",
")",
"if",
"end",
":",
"end",
"=",
"offset",
".",
"rollback",
"(",
"end",
")",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | cftime_range | Return a fixed frequency CFTimeIndex.
Parameters
----------
start : str or cftime.datetime, optional
Left bound for generating dates.
end : str or cftime.datetime, optional
Right bound for generating dates.
periods : integer, optional
Number of periods to generate.
freq ... | xarray/coding/cftime_offsets.py | def cftime_range(start=None, end=None, periods=None, freq='D',
normalize=False, name=None, closed=None,
calendar='standard'):
"""Return a fixed frequency CFTimeIndex.
Parameters
----------
start : str or cftime.datetime, optional
Left bound for generating dates... | def cftime_range(start=None, end=None, periods=None, freq='D',
normalize=False, name=None, closed=None,
calendar='standard'):
"""Return a fixed frequency CFTimeIndex.
Parameters
----------
start : str or cftime.datetime, optional
Left bound for generating dates... | [
"Return",
"a",
"fixed",
"frequency",
"CFTimeIndex",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L782-L991 | [
"def",
"cftime_range",
"(",
"start",
"=",
"None",
",",
"end",
"=",
"None",
",",
"periods",
"=",
"None",
",",
"freq",
"=",
"'D'",
",",
"normalize",
"=",
"False",
",",
"name",
"=",
"None",
",",
"closed",
"=",
"None",
",",
"calendar",
"=",
"'standard'",... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | QuarterOffset.onOffset | Check if the given date is in the set of possible dates created
using a length-one version of this offset class. | xarray/coding/cftime_offsets.py | def onOffset(self, date):
"""Check if the given date is in the set of possible dates created
using a length-one version of this offset class."""
mod_month = (date.month - self.month) % 3
return mod_month == 0 and date.day == self._get_offset_day(date) | def onOffset(self, date):
"""Check if the given date is in the set of possible dates created
using a length-one version of this offset class."""
mod_month = (date.month - self.month) % 3
return mod_month == 0 and date.day == self._get_offset_day(date) | [
"Check",
"if",
"the",
"given",
"date",
"is",
"in",
"the",
"set",
"of",
"possible",
"dates",
"created",
"using",
"a",
"length",
"-",
"one",
"version",
"of",
"this",
"offset",
"class",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L375-L379 | [
"def",
"onOffset",
"(",
"self",
",",
"date",
")",
":",
"mod_month",
"=",
"(",
"date",
".",
"month",
"-",
"self",
".",
"month",
")",
"%",
"3",
"return",
"mod_month",
"==",
"0",
"and",
"date",
".",
"day",
"==",
"self",
".",
"_get_offset_day",
"(",
"d... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | QuarterBegin.rollforward | Roll date forward to nearest start of quarter | xarray/coding/cftime_offsets.py | def rollforward(self, date):
"""Roll date forward to nearest start of quarter"""
if self.onOffset(date):
return date
else:
return date + QuarterBegin(month=self.month) | def rollforward(self, date):
"""Roll date forward to nearest start of quarter"""
if self.onOffset(date):
return date
else:
return date + QuarterBegin(month=self.month) | [
"Roll",
"date",
"forward",
"to",
"nearest",
"start",
"of",
"quarter"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L412-L417 | [
"def",
"rollforward",
"(",
"self",
",",
"date",
")",
":",
"if",
"self",
".",
"onOffset",
"(",
"date",
")",
":",
"return",
"date",
"else",
":",
"return",
"date",
"+",
"QuarterBegin",
"(",
"month",
"=",
"self",
".",
"month",
")"
] | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | QuarterBegin.rollback | Roll date backward to nearest start of quarter | xarray/coding/cftime_offsets.py | def rollback(self, date):
"""Roll date backward to nearest start of quarter"""
if self.onOffset(date):
return date
else:
return date - QuarterBegin(month=self.month) | def rollback(self, date):
"""Roll date backward to nearest start of quarter"""
if self.onOffset(date):
return date
else:
return date - QuarterBegin(month=self.month) | [
"Roll",
"date",
"backward",
"to",
"nearest",
"start",
"of",
"quarter"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L419-L424 | [
"def",
"rollback",
"(",
"self",
",",
"date",
")",
":",
"if",
"self",
".",
"onOffset",
"(",
"date",
")",
":",
"return",
"date",
"else",
":",
"return",
"date",
"-",
"QuarterBegin",
"(",
"month",
"=",
"self",
".",
"month",
")"
] | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | QuarterEnd.rollforward | Roll date forward to nearest end of quarter | xarray/coding/cftime_offsets.py | def rollforward(self, date):
"""Roll date forward to nearest end of quarter"""
if self.onOffset(date):
return date
else:
return date + QuarterEnd(month=self.month) | def rollforward(self, date):
"""Roll date forward to nearest end of quarter"""
if self.onOffset(date):
return date
else:
return date + QuarterEnd(month=self.month) | [
"Roll",
"date",
"forward",
"to",
"nearest",
"end",
"of",
"quarter"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L437-L442 | [
"def",
"rollforward",
"(",
"self",
",",
"date",
")",
":",
"if",
"self",
".",
"onOffset",
"(",
"date",
")",
":",
"return",
"date",
"else",
":",
"return",
"date",
"+",
"QuarterEnd",
"(",
"month",
"=",
"self",
".",
"month",
")"
] | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | QuarterEnd.rollback | Roll date backward to nearest end of quarter | xarray/coding/cftime_offsets.py | def rollback(self, date):
"""Roll date backward to nearest end of quarter"""
if self.onOffset(date):
return date
else:
return date - QuarterEnd(month=self.month) | def rollback(self, date):
"""Roll date backward to nearest end of quarter"""
if self.onOffset(date):
return date
else:
return date - QuarterEnd(month=self.month) | [
"Roll",
"date",
"backward",
"to",
"nearest",
"end",
"of",
"quarter"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L444-L449 | [
"def",
"rollback",
"(",
"self",
",",
"date",
")",
":",
"if",
"self",
".",
"onOffset",
"(",
"date",
")",
":",
"return",
"date",
"else",
":",
"return",
"date",
"-",
"QuarterEnd",
"(",
"month",
"=",
"self",
".",
"month",
")"
] | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | YearBegin.rollforward | Roll date forward to nearest start of year | xarray/coding/cftime_offsets.py | def rollforward(self, date):
"""Roll date forward to nearest start of year"""
if self.onOffset(date):
return date
else:
return date + YearBegin(month=self.month) | def rollforward(self, date):
"""Roll date forward to nearest start of year"""
if self.onOffset(date):
return date
else:
return date + YearBegin(month=self.month) | [
"Roll",
"date",
"forward",
"to",
"nearest",
"start",
"of",
"year"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L498-L503 | [
"def",
"rollforward",
"(",
"self",
",",
"date",
")",
":",
"if",
"self",
".",
"onOffset",
"(",
"date",
")",
":",
"return",
"date",
"else",
":",
"return",
"date",
"+",
"YearBegin",
"(",
"month",
"=",
"self",
".",
"month",
")"
] | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | YearBegin.rollback | Roll date backward to nearest start of year | xarray/coding/cftime_offsets.py | def rollback(self, date):
"""Roll date backward to nearest start of year"""
if self.onOffset(date):
return date
else:
return date - YearBegin(month=self.month) | def rollback(self, date):
"""Roll date backward to nearest start of year"""
if self.onOffset(date):
return date
else:
return date - YearBegin(month=self.month) | [
"Roll",
"date",
"backward",
"to",
"nearest",
"start",
"of",
"year"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L505-L510 | [
"def",
"rollback",
"(",
"self",
",",
"date",
")",
":",
"if",
"self",
".",
"onOffset",
"(",
"date",
")",
":",
"return",
"date",
"else",
":",
"return",
"date",
"-",
"YearBegin",
"(",
"month",
"=",
"self",
".",
"month",
")"
] | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | YearEnd.onOffset | Check if the given date is in the set of possible dates created
using a length-one version of this offset class. | xarray/coding/cftime_offsets.py | def onOffset(self, date):
"""Check if the given date is in the set of possible dates created
using a length-one version of this offset class."""
return date.day == _days_in_month(date) and date.month == self.month | def onOffset(self, date):
"""Check if the given date is in the set of possible dates created
using a length-one version of this offset class."""
return date.day == _days_in_month(date) and date.month == self.month | [
"Check",
"if",
"the",
"given",
"date",
"is",
"in",
"the",
"set",
"of",
"possible",
"dates",
"created",
"using",
"a",
"length",
"-",
"one",
"version",
"of",
"this",
"offset",
"class",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L518-L521 | [
"def",
"onOffset",
"(",
"self",
",",
"date",
")",
":",
"return",
"date",
".",
"day",
"==",
"_days_in_month",
"(",
"date",
")",
"and",
"date",
".",
"month",
"==",
"self",
".",
"month"
] | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | YearEnd.rollforward | Roll date forward to nearest end of year | xarray/coding/cftime_offsets.py | def rollforward(self, date):
"""Roll date forward to nearest end of year"""
if self.onOffset(date):
return date
else:
return date + YearEnd(month=self.month) | def rollforward(self, date):
"""Roll date forward to nearest end of year"""
if self.onOffset(date):
return date
else:
return date + YearEnd(month=self.month) | [
"Roll",
"date",
"forward",
"to",
"nearest",
"end",
"of",
"year"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L523-L528 | [
"def",
"rollforward",
"(",
"self",
",",
"date",
")",
":",
"if",
"self",
".",
"onOffset",
"(",
"date",
")",
":",
"return",
"date",
"else",
":",
"return",
"date",
"+",
"YearEnd",
"(",
"month",
"=",
"self",
".",
"month",
")"
] | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | YearEnd.rollback | Roll date backward to nearest end of year | xarray/coding/cftime_offsets.py | def rollback(self, date):
"""Roll date backward to nearest end of year"""
if self.onOffset(date):
return date
else:
return date - YearEnd(month=self.month) | def rollback(self, date):
"""Roll date backward to nearest end of year"""
if self.onOffset(date):
return date
else:
return date - YearEnd(month=self.month) | [
"Roll",
"date",
"backward",
"to",
"nearest",
"end",
"of",
"year"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/coding/cftime_offsets.py#L530-L535 | [
"def",
"rollback",
"(",
"self",
",",
"date",
")",
":",
"if",
"self",
".",
"onOffset",
"(",
"date",
")",
":",
"return",
"date",
"else",
":",
"return",
"date",
"-",
"YearEnd",
"(",
"month",
"=",
"self",
".",
"month",
")"
] | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | pretty_print | Given an object `x`, call `str(x)` and format the returned string so
that it is numchars long, padding with trailing spaces or truncating with
ellipses as necessary | xarray/core/formatting.py | def pretty_print(x, numchars):
"""Given an object `x`, call `str(x)` and format the returned string so
that it is numchars long, padding with trailing spaces or truncating with
ellipses as necessary
"""
s = maybe_truncate(x, numchars)
return s + ' ' * max(numchars - len(s), 0) | def pretty_print(x, numchars):
"""Given an object `x`, call `str(x)` and format the returned string so
that it is numchars long, padding with trailing spaces or truncating with
ellipses as necessary
"""
s = maybe_truncate(x, numchars)
return s + ' ' * max(numchars - len(s), 0) | [
"Given",
"an",
"object",
"x",
"call",
"str",
"(",
"x",
")",
"and",
"format",
"the",
"returned",
"string",
"so",
"that",
"it",
"is",
"numchars",
"long",
"padding",
"with",
"trailing",
"spaces",
"or",
"truncating",
"with",
"ellipses",
"as",
"necessary"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/formatting.py#L22-L28 | [
"def",
"pretty_print",
"(",
"x",
",",
"numchars",
")",
":",
"s",
"=",
"maybe_truncate",
"(",
"x",
",",
"numchars",
")",
"return",
"s",
"+",
"' '",
"*",
"max",
"(",
"numchars",
"-",
"len",
"(",
"s",
")",
",",
"0",
")"
] | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | first_n_items | Returns the first n_desired items of an array | xarray/core/formatting.py | def first_n_items(array, n_desired):
"""Returns the first n_desired items of an array"""
# Unfortunately, we can't just do array.flat[:n_desired] here because it
# might not be a numpy.ndarray. Moreover, access to elements of the array
# could be very expensive (e.g. if it's only available over DAP), so... | def first_n_items(array, n_desired):
"""Returns the first n_desired items of an array"""
# Unfortunately, we can't just do array.flat[:n_desired] here because it
# might not be a numpy.ndarray. Moreover, access to elements of the array
# could be very expensive (e.g. if it's only available over DAP), so... | [
"Returns",
"the",
"first",
"n_desired",
"items",
"of",
"an",
"array"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/formatting.py#L56-L73 | [
"def",
"first_n_items",
"(",
"array",
",",
"n_desired",
")",
":",
"# Unfortunately, we can't just do array.flat[:n_desired] here because it",
"# might not be a numpy.ndarray. Moreover, access to elements of the array",
"# could be very expensive (e.g. if it's only available over DAP), so go out"... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | last_n_items | Returns the last n_desired items of an array | xarray/core/formatting.py | def last_n_items(array, n_desired):
"""Returns the last n_desired items of an array"""
# Unfortunately, we can't just do array.flat[-n_desired:] here because it
# might not be a numpy.ndarray. Moreover, access to elements of the array
# could be very expensive (e.g. if it's only available over DAP), so ... | def last_n_items(array, n_desired):
"""Returns the last n_desired items of an array"""
# Unfortunately, we can't just do array.flat[-n_desired:] here because it
# might not be a numpy.ndarray. Moreover, access to elements of the array
# could be very expensive (e.g. if it's only available over DAP), so ... | [
"Returns",
"the",
"last",
"n_desired",
"items",
"of",
"an",
"array"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/formatting.py#L76-L89 | [
"def",
"last_n_items",
"(",
"array",
",",
"n_desired",
")",
":",
"# Unfortunately, we can't just do array.flat[-n_desired:] here because it",
"# might not be a numpy.ndarray. Moreover, access to elements of the array",
"# could be very expensive (e.g. if it's only available over DAP), so go out"... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | last_item | Returns the last item of an array in a list or an empty list. | xarray/core/formatting.py | def last_item(array):
"""Returns the last item of an array in a list or an empty list."""
if array.size == 0:
# work around for https://github.com/numpy/numpy/issues/5195
return []
indexer = (slice(-1, None),) * array.ndim
return np.ravel(array[indexer]).tolist() | def last_item(array):
"""Returns the last item of an array in a list or an empty list."""
if array.size == 0:
# work around for https://github.com/numpy/numpy/issues/5195
return []
indexer = (slice(-1, None),) * array.ndim
return np.ravel(array[indexer]).tolist() | [
"Returns",
"the",
"last",
"item",
"of",
"an",
"array",
"in",
"a",
"list",
"or",
"an",
"empty",
"list",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/formatting.py#L92-L99 | [
"def",
"last_item",
"(",
"array",
")",
":",
"if",
"array",
".",
"size",
"==",
"0",
":",
"# work around for https://github.com/numpy/numpy/issues/5195",
"return",
"[",
"]",
"indexer",
"=",
"(",
"slice",
"(",
"-",
"1",
",",
"None",
")",
",",
")",
"*",
"array... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | format_timestamp | Cast given object to a Timestamp and return a nicely formatted string | xarray/core/formatting.py | def format_timestamp(t):
"""Cast given object to a Timestamp and return a nicely formatted string"""
# Timestamp is only valid for 1678 to 2262
try:
datetime_str = str(pd.Timestamp(t))
except OutOfBoundsDatetime:
datetime_str = str(t)
try:
date_str, time_str = datetime_str.s... | def format_timestamp(t):
"""Cast given object to a Timestamp and return a nicely formatted string"""
# Timestamp is only valid for 1678 to 2262
try:
datetime_str = str(pd.Timestamp(t))
except OutOfBoundsDatetime:
datetime_str = str(t)
try:
date_str, time_str = datetime_str.s... | [
"Cast",
"given",
"object",
"to",
"a",
"Timestamp",
"and",
"return",
"a",
"nicely",
"formatted",
"string"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/formatting.py#L102-L119 | [
"def",
"format_timestamp",
"(",
"t",
")",
":",
"# Timestamp is only valid for 1678 to 2262",
"try",
":",
"datetime_str",
"=",
"str",
"(",
"pd",
".",
"Timestamp",
"(",
"t",
")",
")",
"except",
"OutOfBoundsDatetime",
":",
"datetime_str",
"=",
"str",
"(",
"t",
")... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | format_timedelta | Cast given object to a Timestamp and return a nicely formatted string | xarray/core/formatting.py | def format_timedelta(t, timedelta_format=None):
"""Cast given object to a Timestamp and return a nicely formatted string"""
timedelta_str = str(pd.Timedelta(t))
try:
days_str, time_str = timedelta_str.split(' days ')
except ValueError:
# catch NaT and others that don't split nicely
... | def format_timedelta(t, timedelta_format=None):
"""Cast given object to a Timestamp and return a nicely formatted string"""
timedelta_str = str(pd.Timedelta(t))
try:
days_str, time_str = timedelta_str.split(' days ')
except ValueError:
# catch NaT and others that don't split nicely
... | [
"Cast",
"given",
"object",
"to",
"a",
"Timestamp",
"and",
"return",
"a",
"nicely",
"formatted",
"string"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/formatting.py#L122-L136 | [
"def",
"format_timedelta",
"(",
"t",
",",
"timedelta_format",
"=",
"None",
")",
":",
"timedelta_str",
"=",
"str",
"(",
"pd",
".",
"Timedelta",
"(",
"t",
")",
")",
"try",
":",
"days_str",
",",
"time_str",
"=",
"timedelta_str",
".",
"split",
"(",
"' days '... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | format_item | Returns a succinct summary of an object as a string | xarray/core/formatting.py | def format_item(x, timedelta_format=None, quote_strings=True):
"""Returns a succinct summary of an object as a string"""
if isinstance(x, (np.datetime64, datetime)):
return format_timestamp(x)
if isinstance(x, (np.timedelta64, timedelta)):
return format_timedelta(x, timedelta_format=timedelt... | def format_item(x, timedelta_format=None, quote_strings=True):
"""Returns a succinct summary of an object as a string"""
if isinstance(x, (np.datetime64, datetime)):
return format_timestamp(x)
if isinstance(x, (np.timedelta64, timedelta)):
return format_timedelta(x, timedelta_format=timedelt... | [
"Returns",
"a",
"succinct",
"summary",
"of",
"an",
"object",
"as",
"a",
"string"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/formatting.py#L139-L150 | [
"def",
"format_item",
"(",
"x",
",",
"timedelta_format",
"=",
"None",
",",
"quote_strings",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"(",
"np",
".",
"datetime64",
",",
"datetime",
")",
")",
":",
"return",
"format_timestamp",
"(",
"x",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | format_items | Returns a succinct summaries of all items in a sequence as strings | xarray/core/formatting.py | def format_items(x):
"""Returns a succinct summaries of all items in a sequence as strings"""
x = np.asarray(x)
timedelta_format = 'datetime'
if np.issubdtype(x.dtype, np.timedelta64):
x = np.asarray(x, dtype='timedelta64[ns]')
day_part = (x[~pd.isnull(x)]
.astype('ti... | def format_items(x):
"""Returns a succinct summaries of all items in a sequence as strings"""
x = np.asarray(x)
timedelta_format = 'datetime'
if np.issubdtype(x.dtype, np.timedelta64):
x = np.asarray(x, dtype='timedelta64[ns]')
day_part = (x[~pd.isnull(x)]
.astype('ti... | [
"Returns",
"a",
"succinct",
"summaries",
"of",
"all",
"items",
"in",
"a",
"sequence",
"as",
"strings"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/formatting.py#L153-L170 | [
"def",
"format_items",
"(",
"x",
")",
":",
"x",
"=",
"np",
".",
"asarray",
"(",
"x",
")",
"timedelta_format",
"=",
"'datetime'",
"if",
"np",
".",
"issubdtype",
"(",
"x",
".",
"dtype",
",",
"np",
".",
"timedelta64",
")",
":",
"x",
"=",
"np",
".",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | format_array_flat | Return a formatted string for as many items in the flattened version of
array that will fit within max_width characters. | xarray/core/formatting.py | def format_array_flat(array, max_width):
"""Return a formatted string for as many items in the flattened version of
array that will fit within max_width characters.
"""
# every item will take up at least two characters, but we always want to
# print at least first and last items
max_possibly_rel... | def format_array_flat(array, max_width):
"""Return a formatted string for as many items in the flattened version of
array that will fit within max_width characters.
"""
# every item will take up at least two characters, but we always want to
# print at least first and last items
max_possibly_rel... | [
"Return",
"a",
"formatted",
"string",
"for",
"as",
"many",
"items",
"in",
"the",
"flattened",
"version",
"of",
"array",
"that",
"will",
"fit",
"within",
"max_width",
"characters",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/formatting.py#L173-L208 | [
"def",
"format_array_flat",
"(",
"array",
",",
"max_width",
")",
":",
"# every item will take up at least two characters, but we always want to",
"# print at least first and last items",
"max_possibly_relevant",
"=",
"min",
"(",
"max",
"(",
"array",
".",
"size",
",",
"1",
"... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | summarize_attr | Summary for __repr__ - use ``X.attrs[key]`` for full value. | xarray/core/formatting.py | def summarize_attr(key, value, col_width=None):
"""Summary for __repr__ - use ``X.attrs[key]`` for full value."""
# Indent key and add ':', then right-pad if col_width is not None
k_str = ' {}:'.format(key)
if col_width is not None:
k_str = pretty_print(k_str, col_width)
# Replace tabs an... | def summarize_attr(key, value, col_width=None):
"""Summary for __repr__ - use ``X.attrs[key]`` for full value."""
# Indent key and add ':', then right-pad if col_width is not None
k_str = ' {}:'.format(key)
if col_width is not None:
k_str = pretty_print(k_str, col_width)
# Replace tabs an... | [
"Summary",
"for",
"__repr__",
"-",
"use",
"X",
".",
"attrs",
"[",
"key",
"]",
"for",
"full",
"value",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/formatting.py#L265-L275 | [
"def",
"summarize_attr",
"(",
"key",
",",
"value",
",",
"col_width",
"=",
"None",
")",
":",
"# Indent key and add ':', then right-pad if col_width is not None",
"k_str",
"=",
"' {}:'",
".",
"format",
"(",
"key",
")",
"if",
"col_width",
"is",
"not",
"None",
":",... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _get_col_items | Get all column items to format, including both keys of `mapping`
and MultiIndex levels if any. | xarray/core/formatting.py | def _get_col_items(mapping):
"""Get all column items to format, including both keys of `mapping`
and MultiIndex levels if any.
"""
from .variable import IndexVariable
col_items = []
for k, v in mapping.items():
col_items.append(k)
var = getattr(v, 'variable', v)
if isins... | def _get_col_items(mapping):
"""Get all column items to format, including both keys of `mapping`
and MultiIndex levels if any.
"""
from .variable import IndexVariable
col_items = []
for k, v in mapping.items():
col_items.append(k)
var = getattr(v, 'variable', v)
if isins... | [
"Get",
"all",
"column",
"items",
"to",
"format",
"including",
"both",
"keys",
"of",
"mapping",
"and",
"MultiIndex",
"levels",
"if",
"any",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/formatting.py#L281-L295 | [
"def",
"_get_col_items",
"(",
"mapping",
")",
":",
"from",
".",
"variable",
"import",
"IndexVariable",
"col_items",
"=",
"[",
"]",
"for",
"k",
",",
"v",
"in",
"mapping",
".",
"items",
"(",
")",
":",
"col_items",
".",
"append",
"(",
"k",
")",
"var",
"... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | short_dask_repr | Similar to dask.array.DataArray.__repr__, but without
redundant information that's already printed by the repr
function of the xarray wrapper. | xarray/core/formatting.py | def short_dask_repr(array, show_dtype=True):
"""Similar to dask.array.DataArray.__repr__, but without
redundant information that's already printed by the repr
function of the xarray wrapper.
"""
chunksize = tuple(c[0] for c in array.chunks)
if show_dtype:
return 'dask.array<shape={}, dty... | def short_dask_repr(array, show_dtype=True):
"""Similar to dask.array.DataArray.__repr__, but without
redundant information that's already printed by the repr
function of the xarray wrapper.
"""
chunksize = tuple(c[0] for c in array.chunks)
if show_dtype:
return 'dask.array<shape={}, dty... | [
"Similar",
"to",
"dask",
".",
"array",
".",
"DataArray",
".",
"__repr__",
"but",
"without",
"redundant",
"information",
"that",
"s",
"already",
"printed",
"by",
"the",
"repr",
"function",
"of",
"the",
"xarray",
"wrapper",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/formatting.py#L380-L391 | [
"def",
"short_dask_repr",
"(",
"array",
",",
"show_dtype",
"=",
"True",
")",
":",
"chunksize",
"=",
"tuple",
"(",
"c",
"[",
"0",
"]",
"for",
"c",
"in",
"array",
".",
"chunks",
")",
"if",
"show_dtype",
":",
"return",
"'dask.array<shape={}, dtype={}, chunksize... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | Resample._upsample | Dispatch function to call appropriate up-sampling methods on
data.
This method should not be called directly; instead, use one of the
wrapper functions supplied by `Resample`.
Parameters
----------
method : str {'asfreq', 'pad', 'ffill', 'backfill', 'bfill', 'nearest',
... | xarray/core/resample.py | def _upsample(self, method, *args, **kwargs):
"""Dispatch function to call appropriate up-sampling methods on
data.
This method should not be called directly; instead, use one of the
wrapper functions supplied by `Resample`.
Parameters
----------
method : str {'... | def _upsample(self, method, *args, **kwargs):
"""Dispatch function to call appropriate up-sampling methods on
data.
This method should not be called directly; instead, use one of the
wrapper functions supplied by `Resample`.
Parameters
----------
method : str {'... | [
"Dispatch",
"function",
"to",
"call",
"appropriate",
"up",
"-",
"sampling",
"methods",
"on",
"data",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/resample.py#L21-L66 | [
"def",
"_upsample",
"(",
"self",
",",
"method",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"upsampled_index",
"=",
"self",
".",
"_full_index",
"# Drop non-dimension coordinates along the resampled dimension",
"for",
"k",
",",
"v",
"in",
"self",
".",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | Resample._interpolate | Apply scipy.interpolate.interp1d along resampling dimension. | xarray/core/resample.py | def _interpolate(self, kind='linear'):
"""Apply scipy.interpolate.interp1d along resampling dimension."""
# drop any existing non-dimension coordinates along the resampling
# dimension
dummy = self._obj.copy()
for k, v in self._obj.coords.items():
if k != self._dim an... | def _interpolate(self, kind='linear'):
"""Apply scipy.interpolate.interp1d along resampling dimension."""
# drop any existing non-dimension coordinates along the resampling
# dimension
dummy = self._obj.copy()
for k, v in self._obj.coords.items():
if k != self._dim an... | [
"Apply",
"scipy",
".",
"interpolate",
".",
"interp1d",
"along",
"resampling",
"dimension",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/resample.py#L139-L149 | [
"def",
"_interpolate",
"(",
"self",
",",
"kind",
"=",
"'linear'",
")",
":",
"# drop any existing non-dimension coordinates along the resampling",
"# dimension",
"dummy",
"=",
"self",
".",
"_obj",
".",
"copy",
"(",
")",
"for",
"k",
",",
"v",
"in",
"self",
".",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | DataArrayResample.apply | Apply a function over each array in the group and concatenate them
together into a new array.
`func` is called like `func(ar, *args, **kwargs)` for each array `ar`
in this group.
Apply uses heuristics (like `pandas.GroupBy.apply`) to figure out how
to stack together the array. ... | xarray/core/resample.py | def apply(self, func, shortcut=False, args=(), **kwargs):
"""Apply a function over each array in the group and concatenate them
together into a new array.
`func` is called like `func(ar, *args, **kwargs)` for each array `ar`
in this group.
Apply uses heuristics (like `pandas.Gr... | def apply(self, func, shortcut=False, args=(), **kwargs):
"""Apply a function over each array in the group and concatenate them
together into a new array.
`func` is called like `func(ar, *args, **kwargs)` for each array `ar`
in this group.
Apply uses heuristics (like `pandas.Gr... | [
"Apply",
"a",
"function",
"over",
"each",
"array",
"in",
"the",
"group",
"and",
"concatenate",
"them",
"together",
"into",
"a",
"new",
"array",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/resample.py#L168-L219 | [
"def",
"apply",
"(",
"self",
",",
"func",
",",
"shortcut",
"=",
"False",
",",
"args",
"=",
"(",
")",
",",
"*",
"*",
"kwargs",
")",
":",
"combined",
"=",
"super",
"(",
"DataArrayResample",
",",
"self",
")",
".",
"apply",
"(",
"func",
",",
"shortcut"... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | DatasetResample.apply | Apply a function over each Dataset in the groups generated for
resampling and concatenate them together into a new Dataset.
`func` is called like `func(ds, *args, **kwargs)` for each dataset `ds`
in this group.
Apply uses heuristics (like `pandas.GroupBy.apply`) to figure out how
... | xarray/core/resample.py | def apply(self, func, args=(), **kwargs):
"""Apply a function over each Dataset in the groups generated for
resampling and concatenate them together into a new Dataset.
`func` is called like `func(ds, *args, **kwargs)` for each dataset `ds`
in this group.
Apply uses heuristics... | def apply(self, func, args=(), **kwargs):
"""Apply a function over each Dataset in the groups generated for
resampling and concatenate them together into a new Dataset.
`func` is called like `func(ds, *args, **kwargs)` for each dataset `ds`
in this group.
Apply uses heuristics... | [
"Apply",
"a",
"function",
"over",
"each",
"Dataset",
"in",
"the",
"groups",
"generated",
"for",
"resampling",
"and",
"concatenate",
"them",
"together",
"into",
"a",
"new",
"Dataset",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/resample.py#L241-L274 | [
"def",
"apply",
"(",
"self",
",",
"func",
",",
"args",
"=",
"(",
")",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
".",
"pop",
"(",
"'shortcut'",
",",
"None",
")",
"# ignore shortcut if set (for now)",
"applied",
"=",
"(",
"func",
"(",
"ds",
",",
"*"... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | DatasetResample.reduce | Reduce the items in this group by applying `func` along the
pre-defined resampling dimension.
Parameters
----------
func : function
Function which can be called in the form
`func(x, axis=axis, **kwargs)` to return the result of collapsing
an np.ndarra... | xarray/core/resample.py | def reduce(self, func, dim=None, keep_attrs=None, **kwargs):
"""Reduce the items in this group by applying `func` along the
pre-defined resampling dimension.
Parameters
----------
func : function
Function which can be called in the form
`func(x, axis=axis... | def reduce(self, func, dim=None, keep_attrs=None, **kwargs):
"""Reduce the items in this group by applying `func` along the
pre-defined resampling dimension.
Parameters
----------
func : function
Function which can be called in the form
`func(x, axis=axis... | [
"Reduce",
"the",
"items",
"in",
"this",
"group",
"by",
"applying",
"func",
"along",
"the",
"pre",
"-",
"defined",
"resampling",
"dimension",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/resample.py#L276-L305 | [
"def",
"reduce",
"(",
"self",
",",
"func",
",",
"dim",
"=",
"None",
",",
"keep_attrs",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"dim",
"==",
"DEFAULT_DIMS",
":",
"dim",
"=",
"None",
"return",
"super",
"(",
"DatasetResample",
",",
"self",... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | default_indexes | Default indexes for a Dataset/DataArray.
Parameters
----------
coords : Mapping[Any, xarray.Variable]
Coordinate variables from which to draw default indexes.
dims : iterable
Iterable of dimension names.
Returns
-------
Mapping from indexing keys (levels/dimension names) to ... | xarray/core/indexes.py | def default_indexes(
coords: Mapping[Any, Variable],
dims: Iterable,
) -> 'OrderedDict[Any, pd.Index]':
"""Default indexes for a Dataset/DataArray.
Parameters
----------
coords : Mapping[Any, xarray.Variable]
Coordinate variables from which to draw default indexes.
dims : iterable
... | def default_indexes(
coords: Mapping[Any, Variable],
dims: Iterable,
) -> 'OrderedDict[Any, pd.Index]':
"""Default indexes for a Dataset/DataArray.
Parameters
----------
coords : Mapping[Any, xarray.Variable]
Coordinate variables from which to draw default indexes.
dims : iterable
... | [
"Default",
"indexes",
"for",
"a",
"Dataset",
"/",
"DataArray",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/indexes.py#L39-L58 | [
"def",
"default_indexes",
"(",
"coords",
":",
"Mapping",
"[",
"Any",
",",
"Variable",
"]",
",",
"dims",
":",
"Iterable",
",",
")",
"->",
"'OrderedDict[Any, pd.Index]'",
":",
"return",
"OrderedDict",
"(",
"(",
"key",
",",
"coords",
"[",
"key",
"]",
".",
"... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | isel_variable_and_index | Index a Variable and pandas.Index together. | xarray/core/indexes.py | def isel_variable_and_index(
name: Hashable,
variable: Variable,
index: pd.Index,
indexers: Mapping[Any, Union[slice, Variable]],
) -> Tuple[Variable, Optional[pd.Index]]:
"""Index a Variable and pandas.Index together."""
if not indexers:
# nothing to index
return variable.copy(d... | def isel_variable_and_index(
name: Hashable,
variable: Variable,
index: pd.Index,
indexers: Mapping[Any, Union[slice, Variable]],
) -> Tuple[Variable, Optional[pd.Index]]:
"""Index a Variable and pandas.Index together."""
if not indexers:
# nothing to index
return variable.copy(d... | [
"Index",
"a",
"Variable",
"and",
"pandas",
".",
"Index",
"together",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/indexes.py#L61-L89 | [
"def",
"isel_variable_and_index",
"(",
"name",
":",
"Hashable",
",",
"variable",
":",
"Variable",
",",
"index",
":",
"pd",
".",
"Index",
",",
"indexers",
":",
"Mapping",
"[",
"Any",
",",
"Union",
"[",
"slice",
",",
"Variable",
"]",
"]",
",",
")",
"->",... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | build_output_coords | Build output coordinates for an operation.
Parameters
----------
args : list
List of raw operation arguments. Any valid types for xarray operations
are OK, e.g., scalars, Variable, DataArray, Dataset.
signature : _UfuncSignature
Core dimensions signature for the operation.
e... | xarray/core/computation.py | def build_output_coords(
args: list,
signature: _UFuncSignature,
exclude_dims: AbstractSet = frozenset(),
) -> 'List[OrderedDict[Any, Variable]]':
"""Build output coordinates for an operation.
Parameters
----------
args : list
List of raw operation arguments. Any valid types for xar... | def build_output_coords(
args: list,
signature: _UFuncSignature,
exclude_dims: AbstractSet = frozenset(),
) -> 'List[OrderedDict[Any, Variable]]':
"""Build output coordinates for an operation.
Parameters
----------
args : list
List of raw operation arguments. Any valid types for xar... | [
"Build",
"output",
"coordinates",
"for",
"an",
"operation",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/computation.py#L145-L191 | [
"def",
"build_output_coords",
"(",
"args",
":",
"list",
",",
"signature",
":",
"_UFuncSignature",
",",
"exclude_dims",
":",
"AbstractSet",
"=",
"frozenset",
"(",
")",
",",
")",
"->",
"'List[OrderedDict[Any, Variable]]'",
":",
"input_coords",
"=",
"_get_coord_variabl... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | apply_dataarray_vfunc | Apply a variable level function over DataArray, Variable and/or ndarray
objects. | xarray/core/computation.py | def apply_dataarray_vfunc(
func,
*args,
signature,
join='inner',
exclude_dims=frozenset(),
keep_attrs=False
):
"""Apply a variable level function over DataArray, Variable and/or ndarray
objects.
"""
from .dataarray import DataArray
if len(args) > 1:
args = deep_align... | def apply_dataarray_vfunc(
func,
*args,
signature,
join='inner',
exclude_dims=frozenset(),
keep_attrs=False
):
"""Apply a variable level function over DataArray, Variable and/or ndarray
objects.
"""
from .dataarray import DataArray
if len(args) > 1:
args = deep_align... | [
"Apply",
"a",
"variable",
"level",
"function",
"over",
"DataArray",
"Variable",
"and",
"/",
"or",
"ndarray",
"objects",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/computation.py#L194-L227 | [
"def",
"apply_dataarray_vfunc",
"(",
"func",
",",
"*",
"args",
",",
"signature",
",",
"join",
"=",
"'inner'",
",",
"exclude_dims",
"=",
"frozenset",
"(",
")",
",",
"keep_attrs",
"=",
"False",
")",
":",
"from",
".",
"dataarray",
"import",
"DataArray",
"if",... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | apply_dict_of_variables_vfunc | Apply a variable level function over dicts of DataArray, DataArray,
Variable and ndarray objects. | xarray/core/computation.py | def apply_dict_of_variables_vfunc(
func, *args, signature, join='inner', fill_value=None
):
"""Apply a variable level function over dicts of DataArray, DataArray,
Variable and ndarray objects.
"""
args = [_as_variables_or_variable(arg) for arg in args]
names = join_dict_keys(args, how=join)
... | def apply_dict_of_variables_vfunc(
func, *args, signature, join='inner', fill_value=None
):
"""Apply a variable level function over dicts of DataArray, DataArray,
Variable and ndarray objects.
"""
args = [_as_variables_or_variable(arg) for arg in args]
names = join_dict_keys(args, how=join)
... | [
"Apply",
"a",
"variable",
"level",
"function",
"over",
"dicts",
"of",
"DataArray",
"DataArray",
"Variable",
"and",
"ndarray",
"objects",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/computation.py#L305-L322 | [
"def",
"apply_dict_of_variables_vfunc",
"(",
"func",
",",
"*",
"args",
",",
"signature",
",",
"join",
"=",
"'inner'",
",",
"fill_value",
"=",
"None",
")",
":",
"args",
"=",
"[",
"_as_variables_or_variable",
"(",
"arg",
")",
"for",
"arg",
"in",
"args",
"]",... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _fast_dataset | Create a dataset as quickly as possible.
Beware: the `variables` OrderedDict is modified INPLACE. | xarray/core/computation.py | def _fast_dataset(
variables: 'OrderedDict[Any, Variable]',
coord_variables: Mapping[Any, Variable],
) -> 'Dataset':
"""Create a dataset as quickly as possible.
Beware: the `variables` OrderedDict is modified INPLACE.
"""
from .dataset import Dataset
variables.update(coord_variables)
co... | def _fast_dataset(
variables: 'OrderedDict[Any, Variable]',
coord_variables: Mapping[Any, Variable],
) -> 'Dataset':
"""Create a dataset as quickly as possible.
Beware: the `variables` OrderedDict is modified INPLACE.
"""
from .dataset import Dataset
variables.update(coord_variables)
co... | [
"Create",
"a",
"dataset",
"as",
"quickly",
"as",
"possible",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/computation.py#L325-L336 | [
"def",
"_fast_dataset",
"(",
"variables",
":",
"'OrderedDict[Any, Variable]'",
",",
"coord_variables",
":",
"Mapping",
"[",
"Any",
",",
"Variable",
"]",
",",
")",
"->",
"'Dataset'",
":",
"from",
".",
"dataset",
"import",
"Dataset",
"variables",
".",
"update",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | apply_dataset_vfunc | Apply a variable level function over Dataset, dict of DataArray,
DataArray, Variable and/or ndarray objects. | xarray/core/computation.py | def apply_dataset_vfunc(
func,
*args,
signature,
join='inner',
dataset_join='exact',
fill_value=_NO_FILL_VALUE,
exclude_dims=frozenset(),
keep_attrs=False
):
"""Apply a variable level function over Dataset, dict of DataArray,
DataArray, Variable and/or ndarray objects.
"""
... | def apply_dataset_vfunc(
func,
*args,
signature,
join='inner',
dataset_join='exact',
fill_value=_NO_FILL_VALUE,
exclude_dims=frozenset(),
keep_attrs=False
):
"""Apply a variable level function over Dataset, dict of DataArray,
DataArray, Variable and/or ndarray objects.
"""
... | [
"Apply",
"a",
"variable",
"level",
"function",
"over",
"Dataset",
"dict",
"of",
"DataArray",
"DataArray",
"Variable",
"and",
"/",
"or",
"ndarray",
"objects",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/computation.py#L339-L384 | [
"def",
"apply_dataset_vfunc",
"(",
"func",
",",
"*",
"args",
",",
"signature",
",",
"join",
"=",
"'inner'",
",",
"dataset_join",
"=",
"'exact'",
",",
"fill_value",
"=",
"_NO_FILL_VALUE",
",",
"exclude_dims",
"=",
"frozenset",
"(",
")",
",",
"keep_attrs",
"="... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _iter_over_selections | Iterate over selections of an xarray object in the provided order. | xarray/core/computation.py | def _iter_over_selections(obj, dim, values):
"""Iterate over selections of an xarray object in the provided order."""
from .groupby import _dummy_copy
dummy = None
for value in values:
try:
obj_sel = obj.sel(**{dim: value})
except (KeyError, IndexError):
if dummy... | def _iter_over_selections(obj, dim, values):
"""Iterate over selections of an xarray object in the provided order."""
from .groupby import _dummy_copy
dummy = None
for value in values:
try:
obj_sel = obj.sel(**{dim: value})
except (KeyError, IndexError):
if dummy... | [
"Iterate",
"over",
"selections",
"of",
"an",
"xarray",
"object",
"in",
"the",
"provided",
"order",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/computation.py#L387-L399 | [
"def",
"_iter_over_selections",
"(",
"obj",
",",
"dim",
",",
"values",
")",
":",
"from",
".",
"groupby",
"import",
"_dummy_copy",
"dummy",
"=",
"None",
"for",
"value",
"in",
"values",
":",
"try",
":",
"obj_sel",
"=",
"obj",
".",
"sel",
"(",
"*",
"*",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | apply_groupby_func | Apply a dataset or datarray level function over GroupBy, Dataset,
DataArray, Variable and/or ndarray objects. | xarray/core/computation.py | def apply_groupby_func(func, *args):
"""Apply a dataset or datarray level function over GroupBy, Dataset,
DataArray, Variable and/or ndarray objects.
"""
from .groupby import GroupBy, peek_at
from .variable import Variable
groupbys = [arg for arg in args if isinstance(arg, GroupBy)]
assert ... | def apply_groupby_func(func, *args):
"""Apply a dataset or datarray level function over GroupBy, Dataset,
DataArray, Variable and/or ndarray objects.
"""
from .groupby import GroupBy, peek_at
from .variable import Variable
groupbys = [arg for arg in args if isinstance(arg, GroupBy)]
assert ... | [
"Apply",
"a",
"dataset",
"or",
"datarray",
"level",
"function",
"over",
"GroupBy",
"Dataset",
"DataArray",
"Variable",
"and",
"/",
"or",
"ndarray",
"objects",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/computation.py#L402-L442 | [
"def",
"apply_groupby_func",
"(",
"func",
",",
"*",
"args",
")",
":",
"from",
".",
"groupby",
"import",
"GroupBy",
",",
"peek_at",
"from",
".",
"variable",
"import",
"Variable",
"groupbys",
"=",
"[",
"arg",
"for",
"arg",
"in",
"args",
"if",
"isinstance",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | apply_variable_ufunc | Apply a ndarray level function over Variable and/or ndarray objects. | xarray/core/computation.py | def apply_variable_ufunc(
func,
*args,
signature,
exclude_dims=frozenset(),
dask='forbidden',
output_dtypes=None,
output_sizes=None,
keep_attrs=False
):
"""Apply a ndarray level function over Variable and/or ndarray objects.
"""
from .variable import Variable, as_compatible_d... | def apply_variable_ufunc(
func,
*args,
signature,
exclude_dims=frozenset(),
dask='forbidden',
output_dtypes=None,
output_sizes=None,
keep_attrs=False
):
"""Apply a ndarray level function over Variable and/or ndarray objects.
"""
from .variable import Variable, as_compatible_d... | [
"Apply",
"a",
"ndarray",
"level",
"function",
"over",
"Variable",
"and",
"/",
"or",
"ndarray",
"objects",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/computation.py#L519-L602 | [
"def",
"apply_variable_ufunc",
"(",
"func",
",",
"*",
"args",
",",
"signature",
",",
"exclude_dims",
"=",
"frozenset",
"(",
")",
",",
"dask",
"=",
"'forbidden'",
",",
"output_dtypes",
"=",
"None",
",",
"output_sizes",
"=",
"None",
",",
"keep_attrs",
"=",
"... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | apply_array_ufunc | Apply a ndarray level function over ndarray objects. | xarray/core/computation.py | def apply_array_ufunc(func, *args, dask='forbidden'):
"""Apply a ndarray level function over ndarray objects."""
if any(isinstance(arg, dask_array_type) for arg in args):
if dask == 'forbidden':
raise ValueError('apply_ufunc encountered a dask array on an '
'argu... | def apply_array_ufunc(func, *args, dask='forbidden'):
"""Apply a ndarray level function over ndarray objects."""
if any(isinstance(arg, dask_array_type) for arg in args):
if dask == 'forbidden':
raise ValueError('apply_ufunc encountered a dask array on an '
'argu... | [
"Apply",
"a",
"ndarray",
"level",
"function",
"over",
"ndarray",
"objects",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/computation.py#L663-L680 | [
"def",
"apply_array_ufunc",
"(",
"func",
",",
"*",
"args",
",",
"dask",
"=",
"'forbidden'",
")",
":",
"if",
"any",
"(",
"isinstance",
"(",
"arg",
",",
"dask_array_type",
")",
"for",
"arg",
"in",
"args",
")",
":",
"if",
"dask",
"==",
"'forbidden'",
":",... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | apply_ufunc | Apply a vectorized function for unlabeled arrays on xarray objects.
The function will be mapped over the data variable(s) of the input
arguments using xarray's standard rules for labeled computation, including
alignment, broadcasting, looping over GroupBy/Dataset variables, and
merging of coordinates.
... | xarray/core/computation.py | def apply_ufunc(
func: Callable,
*args: Any,
input_core_dims: Optional[Sequence[Sequence]] = None,
output_core_dims: Optional[Sequence[Sequence]] = ((),),
exclude_dims: AbstractSet = frozenset(),
vectorize: bool = False,
join: str = 'exact',
dataset_join: str = 'exact',
dataset_fill_... | def apply_ufunc(
func: Callable,
*args: Any,
input_core_dims: Optional[Sequence[Sequence]] = None,
output_core_dims: Optional[Sequence[Sequence]] = ((),),
exclude_dims: AbstractSet = frozenset(),
vectorize: bool = False,
join: str = 'exact',
dataset_join: str = 'exact',
dataset_fill_... | [
"Apply",
"a",
"vectorized",
"function",
"for",
"unlabeled",
"arrays",
"on",
"xarray",
"objects",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/computation.py#L683-L973 | [
"def",
"apply_ufunc",
"(",
"func",
":",
"Callable",
",",
"*",
"args",
":",
"Any",
",",
"input_core_dims",
":",
"Optional",
"[",
"Sequence",
"[",
"Sequence",
"]",
"]",
"=",
"None",
",",
"output_core_dims",
":",
"Optional",
"[",
"Sequence",
"[",
"Sequence",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | dot | Generalized dot product for xarray objects. Like np.einsum, but
provides a simpler interface based on array dimensions.
Parameters
----------
arrays: DataArray (or Variable) objects
Arrays to compute.
dims: str or tuple of strings, optional
Which dimensions to sum over.
If n... | xarray/core/computation.py | def dot(*arrays, dims=None, **kwargs):
"""Generalized dot product for xarray objects. Like np.einsum, but
provides a simpler interface based on array dimensions.
Parameters
----------
arrays: DataArray (or Variable) objects
Arrays to compute.
dims: str or tuple of strings, optional
... | def dot(*arrays, dims=None, **kwargs):
"""Generalized dot product for xarray objects. Like np.einsum, but
provides a simpler interface based on array dimensions.
Parameters
----------
arrays: DataArray (or Variable) objects
Arrays to compute.
dims: str or tuple of strings, optional
... | [
"Generalized",
"dot",
"product",
"for",
"xarray",
"objects",
".",
"Like",
"np",
".",
"einsum",
"but",
"provides",
"a",
"simpler",
"interface",
"based",
"on",
"array",
"dimensions",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/computation.py#L976-L1075 | [
"def",
"dot",
"(",
"*",
"arrays",
",",
"dims",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
".",
"dataarray",
"import",
"DataArray",
"from",
".",
"variable",
"import",
"Variable",
"if",
"any",
"(",
"not",
"isinstance",
"(",
"arr",
",",
"("... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | where | Return elements from `x` or `y` depending on `cond`.
Performs xarray-like broadcasting across input arguments.
Parameters
----------
cond : scalar, array, Variable, DataArray or Dataset with boolean dtype
When True, return values from `x`, otherwise returns values from `y`.
x, y : scalar, ... | xarray/core/computation.py | def where(cond, x, y):
"""Return elements from `x` or `y` depending on `cond`.
Performs xarray-like broadcasting across input arguments.
Parameters
----------
cond : scalar, array, Variable, DataArray or Dataset with boolean dtype
When True, return values from `x`, otherwise returns values... | def where(cond, x, y):
"""Return elements from `x` or `y` depending on `cond`.
Performs xarray-like broadcasting across input arguments.
Parameters
----------
cond : scalar, array, Variable, DataArray or Dataset with boolean dtype
When True, return values from `x`, otherwise returns values... | [
"Return",
"elements",
"from",
"x",
"or",
"y",
"depending",
"on",
"cond",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/computation.py#L1078-L1117 | [
"def",
"where",
"(",
"cond",
",",
"x",
",",
"y",
")",
":",
"# alignment for three arguments is complicated, so don't support it yet",
"return",
"apply_ufunc",
"(",
"duck_array_ops",
".",
"where",
",",
"cond",
",",
"x",
",",
"y",
",",
"join",
"=",
"'exact'",
",",... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _UFuncSignature.to_gufunc_string | Create an equivalent signature string for a NumPy gufunc.
Unlike __str__, handles dimensions that don't map to Python
identifiers. | xarray/core/computation.py | def to_gufunc_string(self):
"""Create an equivalent signature string for a NumPy gufunc.
Unlike __str__, handles dimensions that don't map to Python
identifiers.
"""
all_dims = self.all_core_dims
dims_map = dict(zip(sorted(all_dims), range(len(all_dims))))
input_... | def to_gufunc_string(self):
"""Create an equivalent signature string for a NumPy gufunc.
Unlike __str__, handles dimensions that don't map to Python
identifiers.
"""
all_dims = self.all_core_dims
dims_map = dict(zip(sorted(all_dims), range(len(all_dims))))
input_... | [
"Create",
"an",
"equivalent",
"signature",
"string",
"for",
"a",
"NumPy",
"gufunc",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/computation.py#L104-L117 | [
"def",
"to_gufunc_string",
"(",
"self",
")",
":",
"all_dims",
"=",
"self",
".",
"all_core_dims",
"dims_map",
"=",
"dict",
"(",
"zip",
"(",
"sorted",
"(",
"all_dims",
")",
",",
"range",
"(",
"len",
"(",
"all_dims",
")",
")",
")",
")",
"input_core_dims",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | inverse_permutation | Return indices for an inverse permutation.
Parameters
----------
indices : 1D np.ndarray with dtype=int
Integer positions to assign elements to.
Returns
-------
inverse_permutation : 1D np.ndarray with dtype=int
Integer indices to take from the original array to create the
... | xarray/core/nputils.py | def inverse_permutation(indices):
"""Return indices for an inverse permutation.
Parameters
----------
indices : 1D np.ndarray with dtype=int
Integer positions to assign elements to.
Returns
-------
inverse_permutation : 1D np.ndarray with dtype=int
Integer indices to take f... | def inverse_permutation(indices):
"""Return indices for an inverse permutation.
Parameters
----------
indices : 1D np.ndarray with dtype=int
Integer positions to assign elements to.
Returns
-------
inverse_permutation : 1D np.ndarray with dtype=int
Integer indices to take f... | [
"Return",
"indices",
"for",
"an",
"inverse",
"permutation",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/nputils.py#L44-L61 | [
"def",
"inverse_permutation",
"(",
"indices",
")",
":",
"# use intp instead of int64 because of windows :(",
"inverse_permutation",
"=",
"np",
".",
"empty",
"(",
"len",
"(",
"indices",
")",
",",
"dtype",
"=",
"np",
".",
"intp",
")",
"inverse_permutation",
"[",
"in... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _is_contiguous | Given a non-empty list, does it consist of contiguous integers? | xarray/core/nputils.py | def _is_contiguous(positions):
"""Given a non-empty list, does it consist of contiguous integers?"""
previous = positions[0]
for current in positions[1:]:
if current != previous + 1:
return False
previous = current
return True | def _is_contiguous(positions):
"""Given a non-empty list, does it consist of contiguous integers?"""
previous = positions[0]
for current in positions[1:]:
if current != previous + 1:
return False
previous = current
return True | [
"Given",
"a",
"non",
"-",
"empty",
"list",
"does",
"it",
"consist",
"of",
"contiguous",
"integers?"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/nputils.py#L90-L97 | [
"def",
"_is_contiguous",
"(",
"positions",
")",
":",
"previous",
"=",
"positions",
"[",
"0",
"]",
"for",
"current",
"in",
"positions",
"[",
"1",
":",
"]",
":",
"if",
"current",
"!=",
"previous",
"+",
"1",
":",
"return",
"False",
"previous",
"=",
"curre... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _advanced_indexer_subspaces | Indices of the advanced indexes subspaces for mixed indexing and vindex. | xarray/core/nputils.py | def _advanced_indexer_subspaces(key):
"""Indices of the advanced indexes subspaces for mixed indexing and vindex.
"""
if not isinstance(key, tuple):
key = (key,)
advanced_index_positions = [i for i, k in enumerate(key)
if not isinstance(k, slice)]
if (not adv... | def _advanced_indexer_subspaces(key):
"""Indices of the advanced indexes subspaces for mixed indexing and vindex.
"""
if not isinstance(key, tuple):
key = (key,)
advanced_index_positions = [i for i, k in enumerate(key)
if not isinstance(k, slice)]
if (not adv... | [
"Indices",
"of",
"the",
"advanced",
"indexes",
"subspaces",
"for",
"mixed",
"indexing",
"and",
"vindex",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/nputils.py#L100-L120 | [
"def",
"_advanced_indexer_subspaces",
"(",
"key",
")",
":",
"if",
"not",
"isinstance",
"(",
"key",
",",
"tuple",
")",
":",
"key",
"=",
"(",
"key",
",",
")",
"advanced_index_positions",
"=",
"[",
"i",
"for",
"i",
",",
"k",
"in",
"enumerate",
"(",
"key",... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | rolling_window | rolling window with padding. | xarray/core/nputils.py | def rolling_window(a, axis, window, center, fill_value):
""" rolling window with padding. """
pads = [(0, 0) for s in a.shape]
if center:
start = int(window / 2) # 10 -> 5, 9 -> 4
end = window - 1 - start
pads[axis] = (start, end)
else:
pads[axis] = (window - 1, 0)
... | def rolling_window(a, axis, window, center, fill_value):
""" rolling window with padding. """
pads = [(0, 0) for s in a.shape]
if center:
start = int(window / 2) # 10 -> 5, 9 -> 4
end = window - 1 - start
pads[axis] = (start, end)
else:
pads[axis] = (window - 1, 0)
... | [
"rolling",
"window",
"with",
"padding",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/nputils.py#L144-L154 | [
"def",
"rolling_window",
"(",
"a",
",",
"axis",
",",
"window",
",",
"center",
",",
"fill_value",
")",
":",
"pads",
"=",
"[",
"(",
"0",
",",
"0",
")",
"for",
"s",
"in",
"a",
".",
"shape",
"]",
"if",
"center",
":",
"start",
"=",
"int",
"(",
"wind... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _rolling_window | Make an ndarray with a rolling window along axis.
Parameters
----------
a : array_like
Array to add rolling window to
axis: int
axis position along which rolling window will be applied.
window : int
Size of rolling window
Returns
-------
Array that is a view of ... | xarray/core/nputils.py | def _rolling_window(a, window, axis=-1):
"""
Make an ndarray with a rolling window along axis.
Parameters
----------
a : array_like
Array to add rolling window to
axis: int
axis position along which rolling window will be applied.
window : int
Size of rolling window
... | def _rolling_window(a, window, axis=-1):
"""
Make an ndarray with a rolling window along axis.
Parameters
----------
a : array_like
Array to add rolling window to
axis: int
axis position along which rolling window will be applied.
window : int
Size of rolling window
... | [
"Make",
"an",
"ndarray",
"with",
"a",
"rolling",
"window",
"along",
"axis",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/nputils.py#L157-L203 | [
"def",
"_rolling_window",
"(",
"a",
",",
"window",
",",
"axis",
"=",
"-",
"1",
")",
":",
"axis",
"=",
"_validate_axis",
"(",
"a",
",",
"axis",
")",
"a",
"=",
"np",
".",
"swapaxes",
"(",
"a",
",",
"axis",
",",
"-",
"1",
")",
"if",
"window",
"<",... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | _get_virtual_variable | Get a virtual variable (e.g., 'time.year' or a MultiIndex level)
from a dict of xarray.Variable objects (if possible) | xarray/core/dataset.py | def _get_virtual_variable(variables, key, level_vars=None, dim_sizes=None):
"""Get a virtual variable (e.g., 'time.year' or a MultiIndex level)
from a dict of xarray.Variable objects (if possible)
"""
if level_vars is None:
level_vars = {}
if dim_sizes is None:
dim_sizes = {}
if... | def _get_virtual_variable(variables, key, level_vars=None, dim_sizes=None):
"""Get a virtual variable (e.g., 'time.year' or a MultiIndex level)
from a dict of xarray.Variable objects (if possible)
"""
if level_vars is None:
level_vars = {}
if dim_sizes is None:
dim_sizes = {}
if... | [
"Get",
"a",
"virtual",
"variable",
"(",
"e",
".",
"g",
".",
"time",
".",
"year",
"or",
"a",
"MultiIndex",
"level",
")",
"from",
"a",
"dict",
"of",
"xarray",
".",
"Variable",
"objects",
"(",
"if",
"possible",
")"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/dataset.py#L53-L95 | [
"def",
"_get_virtual_variable",
"(",
"variables",
",",
"key",
",",
"level_vars",
"=",
"None",
",",
"dim_sizes",
"=",
"None",
")",
":",
"if",
"level_vars",
"is",
"None",
":",
"level_vars",
"=",
"{",
"}",
"if",
"dim_sizes",
"is",
"None",
":",
"dim_sizes",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | calculate_dimensions | Calculate the dimensions corresponding to a set of variables.
Returns dictionary mapping from dimension names to sizes. Raises ValueError
if any of the dimension sizes conflict. | xarray/core/dataset.py | def calculate_dimensions(variables):
"""Calculate the dimensions corresponding to a set of variables.
Returns dictionary mapping from dimension names to sizes. Raises ValueError
if any of the dimension sizes conflict.
"""
dims = OrderedDict()
last_used = {}
scalar_vars = set(k for k, v in v... | def calculate_dimensions(variables):
"""Calculate the dimensions corresponding to a set of variables.
Returns dictionary mapping from dimension names to sizes. Raises ValueError
if any of the dimension sizes conflict.
"""
dims = OrderedDict()
last_used = {}
scalar_vars = set(k for k, v in v... | [
"Calculate",
"the",
"dimensions",
"corresponding",
"to",
"a",
"set",
"of",
"variables",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/dataset.py#L98-L119 | [
"def",
"calculate_dimensions",
"(",
"variables",
")",
":",
"dims",
"=",
"OrderedDict",
"(",
")",
"last_used",
"=",
"{",
"}",
"scalar_vars",
"=",
"set",
"(",
"k",
"for",
"k",
",",
"v",
"in",
"variables",
".",
"items",
"(",
")",
"if",
"not",
"v",
".",
... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | merge_indexes | Merge variables into multi-indexes.
Not public API. Used in Dataset and DataArray set_index
methods. | xarray/core/dataset.py | def merge_indexes(
indexes, # type: Dict[Any, Union[Any, List[Any]]]
variables, # type: Dict[Any, Variable]
coord_names, # type: Set
append=False, # type: bool
):
# type: (...) -> Tuple[OrderedDict[Any, Variable], Set]
"""Merge variables into multi-indexes.
Not public AP... | def merge_indexes(
indexes, # type: Dict[Any, Union[Any, List[Any]]]
variables, # type: Dict[Any, Variable]
coord_names, # type: Set
append=False, # type: bool
):
# type: (...) -> Tuple[OrderedDict[Any, Variable], Set]
"""Merge variables into multi-indexes.
Not public AP... | [
"Merge",
"variables",
"into",
"multi",
"-",
"indexes",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/dataset.py#L122-L191 | [
"def",
"merge_indexes",
"(",
"indexes",
",",
"# type: Dict[Any, Union[Any, List[Any]]]",
"variables",
",",
"# type: Dict[Any, Variable]",
"coord_names",
",",
"# type: Set",
"append",
"=",
"False",
",",
"# type: bool",
")",
":",
"# type: (...) -> Tuple[OrderedDict[Any, Variable]... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | split_indexes | Extract (multi-)indexes (levels) as variables.
Not public API. Used in Dataset and DataArray reset_index
methods. | xarray/core/dataset.py | def split_indexes(
dims_or_levels, # type: Union[Any, List[Any]]
variables, # type: OrderedDict[Any, Variable]
coord_names, # type: Set
level_coords, # type: Dict[Any, Any]
drop=False, # type: bool
):
# type: (...) -> Tuple[OrderedDict[Any, Variable], Set]
"""Extract (multi-)indexes (le... | def split_indexes(
dims_or_levels, # type: Union[Any, List[Any]]
variables, # type: OrderedDict[Any, Variable]
coord_names, # type: Set
level_coords, # type: Dict[Any, Any]
drop=False, # type: bool
):
# type: (...) -> Tuple[OrderedDict[Any, Variable], Set]
"""Extract (multi-)indexes (le... | [
"Extract",
"(",
"multi",
"-",
")",
"indexes",
"(",
"levels",
")",
"as",
"variables",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/dataset.py#L194-L250 | [
"def",
"split_indexes",
"(",
"dims_or_levels",
",",
"# type: Union[Any, List[Any]]",
"variables",
",",
"# type: OrderedDict[Any, Variable]",
"coord_names",
",",
"# type: Set",
"level_coords",
",",
"# type: Dict[Any, Any]",
"drop",
"=",
"False",
",",
"# type: bool",
")",
":"... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | as_dataset | Cast the given object to a Dataset.
Handles Datasets, DataArrays and dictionaries of variables. A new Dataset
object is only created if the provided object is not already one. | xarray/core/dataset.py | def as_dataset(obj):
"""Cast the given object to a Dataset.
Handles Datasets, DataArrays and dictionaries of variables. A new Dataset
object is only created if the provided object is not already one.
"""
if hasattr(obj, 'to_dataset'):
obj = obj.to_dataset()
if not isinstance(obj, Datase... | def as_dataset(obj):
"""Cast the given object to a Dataset.
Handles Datasets, DataArrays and dictionaries of variables. A new Dataset
object is only created if the provided object is not already one.
"""
if hasattr(obj, 'to_dataset'):
obj = obj.to_dataset()
if not isinstance(obj, Datase... | [
"Cast",
"the",
"given",
"object",
"to",
"a",
"Dataset",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/dataset.py#L258-L268 | [
"def",
"as_dataset",
"(",
"obj",
")",
":",
"if",
"hasattr",
"(",
"obj",
",",
"'to_dataset'",
")",
":",
"obj",
"=",
"obj",
".",
"to_dataset",
"(",
")",
"if",
"not",
"isinstance",
"(",
"obj",
",",
"Dataset",
")",
":",
"obj",
"=",
"Dataset",
"(",
"obj... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | DataVariables._ipython_key_completions_ | Provide method for the key-autocompletions in IPython. | xarray/core/dataset.py | def _ipython_key_completions_(self):
"""Provide method for the key-autocompletions in IPython. """
return [key for key in self._dataset._ipython_key_completions_()
if key not in self._dataset._coord_names] | def _ipython_key_completions_(self):
"""Provide method for the key-autocompletions in IPython. """
return [key for key in self._dataset._ipython_key_completions_()
if key not in self._dataset._coord_names] | [
"Provide",
"method",
"for",
"the",
"key",
"-",
"autocompletions",
"in",
"IPython",
"."
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/dataset.py#L300-L303 | [
"def",
"_ipython_key_completions_",
"(",
"self",
")",
":",
"return",
"[",
"key",
"for",
"key",
"in",
"self",
".",
"_dataset",
".",
"_ipython_key_completions_",
"(",
")",
"if",
"key",
"not",
"in",
"self",
".",
"_dataset",
".",
"_coord_names",
"]"
] | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | Dataset._set_init_vars_and_dims | Set the initial value of Dataset variables and dimensions | xarray/core/dataset.py | def _set_init_vars_and_dims(self, data_vars, coords, compat):
"""Set the initial value of Dataset variables and dimensions
"""
both_data_and_coords = [k for k in data_vars if k in coords]
if both_data_and_coords:
raise ValueError('variables %r are found in both data_vars and ... | def _set_init_vars_and_dims(self, data_vars, coords, compat):
"""Set the initial value of Dataset variables and dimensions
"""
both_data_and_coords = [k for k in data_vars if k in coords]
if both_data_and_coords:
raise ValueError('variables %r are found in both data_vars and ... | [
"Set",
"the",
"initial",
"value",
"of",
"Dataset",
"variables",
"and",
"dimensions"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/dataset.py#L393-L409 | [
"def",
"_set_init_vars_and_dims",
"(",
"self",
",",
"data_vars",
",",
"coords",
",",
"compat",
")",
":",
"both_data_and_coords",
"=",
"[",
"k",
"for",
"k",
"in",
"data_vars",
"if",
"k",
"in",
"coords",
"]",
"if",
"both_data_and_coords",
":",
"raise",
"ValueE... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | Dataset.load_store | Create a new dataset from the contents of a backends.*DataStore
object | xarray/core/dataset.py | def load_store(cls, store, decoder=None):
"""Create a new dataset from the contents of a backends.*DataStore
object
"""
variables, attributes = store.load()
if decoder:
variables, attributes = decoder(variables, attributes)
obj = cls(variables, attrs=attribute... | def load_store(cls, store, decoder=None):
"""Create a new dataset from the contents of a backends.*DataStore
object
"""
variables, attributes = store.load()
if decoder:
variables, attributes = decoder(variables, attributes)
obj = cls(variables, attrs=attribute... | [
"Create",
"a",
"new",
"dataset",
"from",
"the",
"contents",
"of",
"a",
"backends",
".",
"*",
"DataStore",
"object"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/dataset.py#L412-L421 | [
"def",
"load_store",
"(",
"cls",
",",
"store",
",",
"decoder",
"=",
"None",
")",
":",
"variables",
",",
"attributes",
"=",
"store",
".",
"load",
"(",
")",
"if",
"decoder",
":",
"variables",
",",
"attributes",
"=",
"decoder",
"(",
"variables",
",",
"att... | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
train | Dataset.attrs | Dictionary of global attributes on this dataset | xarray/core/dataset.py | def attrs(self) -> Mapping:
"""Dictionary of global attributes on this dataset
"""
if self._attrs is None:
self._attrs = OrderedDict()
return self._attrs | def attrs(self) -> Mapping:
"""Dictionary of global attributes on this dataset
"""
if self._attrs is None:
self._attrs = OrderedDict()
return self._attrs | [
"Dictionary",
"of",
"global",
"attributes",
"on",
"this",
"dataset"
] | pydata/xarray | python | https://github.com/pydata/xarray/blob/6d93a95d05bdbfc33fff24064f67d29dd891ab58/xarray/core/dataset.py#L435-L440 | [
"def",
"attrs",
"(",
"self",
")",
"->",
"Mapping",
":",
"if",
"self",
".",
"_attrs",
"is",
"None",
":",
"self",
".",
"_attrs",
"=",
"OrderedDict",
"(",
")",
"return",
"self",
".",
"_attrs"
] | 6d93a95d05bdbfc33fff24064f67d29dd891ab58 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.