2121 assert_no_index_corrupted ,
2222 create_default_index_implicit ,
2323)
24- from xarray .core .types import DataVars , ErrorOptions , Self , T_DataArray , T_Xarray
24+ from xarray .core .types import (
25+ CompatOptions ,
26+ DataVars ,
27+ ErrorOptions ,
28+ Self ,
29+ T_DataArray ,
30+ T_Xarray ,
31+ )
2532from xarray .core .utils import (
2633 Frozen ,
2734 ReprObject ,
3138from xarray .core .variable import Variable , as_variable , calculate_dimensions
3239from xarray .structure .alignment import Aligner
3340from xarray .structure .merge import merge_coordinates_without_align , merge_coords
41+ from xarray .util .deprecation_helpers import CombineKwargDefault
3442
3543if TYPE_CHECKING :
3644 from xarray .core .common import DataWithCoords
@@ -499,18 +507,20 @@ def _drop_coords(self, coord_names):
499507 # redirect to DatasetCoordinates._drop_coords
500508 self ._data .coords ._drop_coords (coord_names )
501509
502- def _merge_raw (self , other , reflexive ):
510+ def _merge_raw (self , other , reflexive , compat : CompatOptions | CombineKwargDefault ):
503511 """For use with binary arithmetic."""
504512 if other is None :
505513 variables = dict (self .variables )
506514 indexes = dict (self .xindexes )
507515 else :
508516 coord_list = [self , other ] if not reflexive else [other , self ]
509- variables , indexes = merge_coordinates_without_align (coord_list )
517+ variables , indexes = merge_coordinates_without_align (
518+ coord_list , compat = compat
519+ )
510520 return variables , indexes
511521
512522 @contextmanager
513- def _merge_inplace (self , other ):
523+ def _merge_inplace (self , other , compat : CompatOptions | CombineKwargDefault ):
514524 """For use with in-place binary arithmetic."""
515525 if other is None :
516526 yield
@@ -523,12 +533,16 @@ def _merge_inplace(self, other):
523533 if k not in self .xindexes
524534 }
525535 variables , indexes = merge_coordinates_without_align (
526- [self , other ], prioritized
536+ [self , other ], prioritized , compat = compat
527537 )
528538 yield
529539 self ._update_coords (variables , indexes )
530540
531- def merge (self , other : Mapping [Any , Any ] | None ) -> Dataset :
541+ def merge (
542+ self ,
543+ other : Mapping [Any , Any ] | None ,
544+ compat : CompatOptions | CombineKwargDefault = "minimal" ,
545+ ) -> Dataset :
532546 """Merge two sets of coordinates to create a new Dataset
533547
534548 The method implements the logic used for joining coordinates in the
@@ -545,6 +559,8 @@ def merge(self, other: Mapping[Any, Any] | None) -> Dataset:
545559 other : dict-like, optional
546560 A :py:class:`Coordinates` object or any mapping that can be turned
547561 into coordinates.
562+ compat : {"identical", "equals", "broadcast_equals", "no_conflicts", "override", "minimal"}, default: "minimal"
563+ Compatibility checks to use between coordinate variables.
548564
549565 Returns
550566 -------
@@ -559,7 +575,7 @@ def merge(self, other: Mapping[Any, Any] | None) -> Dataset:
559575 if not isinstance (other , Coordinates ):
560576 other = Dataset (coords = other ).coords
561577
562- coords , indexes = merge_coordinates_without_align ([self , other ])
578+ coords , indexes = merge_coordinates_without_align ([self , other ], compat = compat )
563579 coord_names = set (coords )
564580 return Dataset ._construct_direct (
565581 variables = coords , coord_names = coord_names , indexes = indexes
0 commit comments