File tree 1 file changed +15
-2
lines changed
1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -579,9 +579,22 @@ def subset(dim, label):
579
579
array .attrs = {}
580
580
return as_variable (array )
581
581
582
- variables = {label : subset (dim , label ) for label in self .get_index (dim )}
583
- variables .update ({k : v for k , v in self ._coords .items () if k != dim })
582
+ variables_from_split = {
583
+ label : subset (dim , label ) for label in self .get_index (dim )
584
+ }
584
585
coord_names = set (self ._coords ) - {dim }
586
+
587
+ ambiguous_vars = set (variables_from_split ) & coord_names
588
+ if ambiguous_vars :
589
+ rename_msg_fmt = ", " .join ([f"{ v } =..." for v in sorted (ambiguous_vars )])
590
+ raise ValueError (
591
+ f"Splitting along the dimension { dim !r} would produce the variables "
592
+ f"{ tuple (sorted (ambiguous_vars ))} which are also existing coordinate "
593
+ f"variables. Use DataArray.rename({ rename_msg_fmt } ) or "
594
+ f"DataArray.assign_coords({ dim } =...) to resolve this ambiguity."
595
+ )
596
+
597
+ variables = variables_from_split | {c : self ._coords [c ] for c in coord_names }
585
598
indexes = filter_indexes_from_coords (self ._indexes , coord_names )
586
599
dataset = Dataset ._construct_direct (
587
600
variables , coord_names , indexes = indexes , attrs = self .attrs
You can’t perform that action at this time.
0 commit comments