You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix DataTree.coords.__setitem__ by adding DataTreeCoordinates class (pydata#9451)
* add a DataTreeCoordinates class
* passing read-only properties tests
* tests for modifying in-place
* WIP making the modification test pass
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* get to the delete tests
* test
* improve error message
* implement delitem
* test KeyError
* subclass Coordinates instead of DatasetCoordinates
* use Frozen(self._data._coord_variables)
* Simplify when to raise KeyError
Co-authored-by: Stephan Hoyer <[email protected]>
* correct bug in suggestion
* Update xarray/core/coordinates.py
Co-authored-by: Stephan Hoyer <[email protected]>
* simplify _update_coords by creating new node data first
* update indexes correctly
* passes test
* update ._drop_indexed_coords
* some mypy fixes
* remove the apparently-unused _drop_indexed_coords method
* fix import error
* test that Dataset and DataArray constructors can handle being passed a DataTreeCoordinates object
* test dt.coords can be passed to DataTree constructor
* improve readability of inline comment
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* initial tests with inherited coords
* ignore typeerror indicating dodgy inheritance
* try to avoid Unbound type error
* cast return value correctly
* cehck that .coords works with inherited coords
* fix data->dataset
* fix return type of __getitem__
* Use .dataset instead of .to_dataset()
Co-authored-by: Stephan Hoyer <[email protected]>
* _check_alignment -> check_alignment
* remove dict comprehension
Co-authored-by: Stephan Hoyer <[email protected]>
* KeyError message formatting
Co-authored-by: Stephan Hoyer <[email protected]>
* keep generic types for .dims and .sizes
* test verifying you cant delete inherited coord
* fix mypy complaint
* type hint as accepting objects
* update note about .dims returning all dims
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Stephan Hoyer <[email protected]>
Dictionary like container for coordinates of a DataTree node (variables + indexes).
796
+
797
+
This collection can be passed directly to the :py:class:`~xarray.Dataset`
798
+
and :py:class:`~xarray.DataArray` constructors via their `coords` argument.
799
+
This will add both the coordinates variables and their index.
800
+
"""
801
+
802
+
# TODO: This only needs to be a separate class from `DatasetCoordinates` because DataTree nodes store their variables differently
803
+
# internally than how Datasets do, see https://github.com/pydata/xarray/issues/9203.
804
+
805
+
_data: DataTree# type: ignore[assignment] # complaining that DataTree is not a subclass of DataWithCoords - this can be fixed by refactoring, see #9203
806
+
807
+
__slots__= ("_data",)
808
+
809
+
def__init__(self, datatree: DataTree):
810
+
self._data=datatree
811
+
812
+
@property
813
+
def_names(self) ->set[Hashable]:
814
+
returnset(self._data._coord_variables)
815
+
816
+
@property
817
+
defdims(self) ->Frozen[Hashable, int]:
818
+
# deliberately display all dims, not just those on coordinate variables - see https://github.com/pydata/xarray/issues/9466
819
+
returnFrozen(self._data.dims)
820
+
821
+
@property
822
+
defdtypes(self) ->Frozen[Hashable, np.dtype]:
823
+
"""Mapping from coordinate names to dtypes.
824
+
825
+
Cannot be modified directly, but is updated when adding new variables.
0 commit comments