Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose "Coordinates" as part of Xarray's public API (#7368)
* add indexes argument to Dataset.__init__ * make indexes arg public for DataArray.__init__ * Indexes constructor updates - easily create an empty Indexes collection - check consistency between indexes and variables * use the generic Mapping[Any, Index] for indexes * add wrap_pandas_multiindex function * do not create default indexes when not desired * fix Dataset dimensions TODO: check indexes shapes / dims for DataArray * copy the coordinate variables of passed indexes * DataArray: check dimensions/shape of index coords * docstrings tweaks * more Indexes safety Since its constructor can now be used publicly. Copy input mappings and check the type of input indexes. * ensure input indexes are Xarray indexes * add .assign_indexes() method * add `IndexedCoordinates` subclass + add `IndexedCoordinates.from_pandas_multiindex` helper. * rollback/update Dataset and DataArray constructors Drop the `indexes` argument or keep it as private API. When a `Coordinates` object is passed as `coords` argument, extract both coordinate variables and indexes and add them to the new Dataset or DataArray. * update docstrings * fix Dataset creation internal error * add IndexedCoordinates.merge_coords * drop IndexedCoordinates and reuse Coordinates * update api docs * make Coordinates init args optional * docstrings updates * convert to base variable when no index is given * raise when an index is given with no variable * skip create default indexes... ... When a Coordinates object is given to the Dataset constructor * invariant checks: maybe skip IndexVariable checks ... when check_default_indexes is False. * add Coordinates tests * more Coordinates tests * add Dataset constructor tests with Coordinates * fix mypy * assign_coords: do not create default indexes... ... when passing a Coordinates object * support alignment of Coordinates * clean-up * fix failing test (dataarray coords not extracted) * fix tests: prevent index conflicts Do not extract multi-coordinate indexes from DataArray if they are overwritten or dropped (dimension coordinate). * add Coordinates.equals and Coordinates.identical * more tests, docstrings, docs * fix assert_* (Coordinates subclasses) * review copy * another few tests * fix mypy * update what's new * do not copy indexes May corrupt multi-coordinate indexes. * add Coordinates fastpath constructor * fix sphinx directive * re-add coord indexes in merge (dataset constructor) This re-enables the optimization in deep_align that skips alignment for any alignable (DataArray) in a dict that matches an index key. * create coords with default idx: try a cleaner impl Coordinate variables and indexes extracted from DataArrays should be merged more properly. * some useful comments for later * xr.merge: add support for Coordinates objects * allow skip align for object(s) in merge_core This fixes the decrease in performance observed in Dataset creation benchmarks. When creating a new Dataset, the variables and indexes in `Coordinates` should already be aligned together so it doesn't need to go through the complex alignment logic once again. `Coordinates` indexes are still used to align data variables. * fix mypy * what's new tweaks * align Coordinates callbacks: don't reindex data vars * fix Coordinates._overwrite_indexes callback mypy was rightfully complaining. This callback is called from Aligner only, which passes the first two arguments and ignores the rest. * remove merge_coords * futurewarning: pass multi-index via data vars * review comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix circulat imports * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * typing: add Alignable protocol class * try fixing mypy error (Self redefinition) * remove Coordinate alias of Variable Much water has flowed under the bridge since it has been renamed. * fix groupby test * doc: remove merge_coords in api reference * doc: improve docstrings and glossary * use Self type annotation in Coordinate class * better comment * fix Self undefined error with python < 3.11 Pyright displays an info message "Self is not valid in this context" but most important this should avoid runtime errors with python < 3.11. --------- Co-authored-by: Illviljan <14371165+Illviljan@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com>
- Loading branch information