Define whether or not an index coordinate variable should be added to a new DataArray. This method is called repeatedly for each Variable associated with this index when creating a new DataArray (via its constructor or from a Dataset) or updating an existing one. The
(
self,
name: Hashable,
var: Variable,
dims: set[Hashable],
)
| 203 | return {} |
| 204 | |
| 205 | def should_add_coord_to_array( |
| 206 | self, |
| 207 | name: Hashable, |
| 208 | var: Variable, |
| 209 | dims: set[Hashable], |
| 210 | ) -> bool: |
| 211 | """Define whether or not an index coordinate variable should be added to |
| 212 | a new DataArray. |
| 213 | |
| 214 | This method is called repeatedly for each Variable associated with this |
| 215 | index when creating a new DataArray (via its constructor or from a |
| 216 | Dataset) or updating an existing one. The variables associated with this |
| 217 | index are the ones passed to :py:meth:`Index.from_variables` and/or |
| 218 | returned by :py:meth:`Index.create_variables`. |
| 219 | |
| 220 | By default returns ``True`` if the dimensions of the coordinate variable |
| 221 | are a subset of the array dimensions and ``False`` otherwise (DataArray |
| 222 | model). This default behavior may be overridden in Index subclasses to |
| 223 | bypass strict conformance with the DataArray model. This is useful for |
| 224 | example to include the (n+1)-dimensional cell boundary coordinate |
| 225 | associated with an interval index. |
| 226 | |
| 227 | Returning ``False`` will either: |
| 228 | |
| 229 | - raise a :py:class:`CoordinateValidationError` when passing the |
| 230 | coordinate directly to a new or an existing DataArray, e.g., via |
| 231 | ``DataArray.__init__()`` or ``DataArray.assign_coords()`` |
| 232 | |
| 233 | - drop the coordinate (and therefore drop the index) when a new |
| 234 | DataArray is constructed by indexing a Dataset |
| 235 | |
| 236 | Parameters |
| 237 | ---------- |
| 238 | name : Hashable |
| 239 | Name of a coordinate variable associated to this index. |
| 240 | var : Variable |
| 241 | Coordinate variable object. |
| 242 | dims: tuple |
| 243 | Dimensions of the new DataArray object being created. |
| 244 | |
| 245 | """ |
| 246 | return all(d in dims for d in var.dims) |
| 247 | |
| 248 | def to_pandas_index(self) -> pd.Index: |
| 249 | """Cast this xarray index to a pandas.Index object or raise a |
no outgoing calls
no test coverage detected