@@ -136,6 +136,14 @@ def merge_indexes(
136136 names , labels , levels = [], [], []
137137 current_index_variable = variables .get (dim )
138138
139+ for n in var_names :
140+ var = variables [n ]
141+ if (current_index_variable is not None and
142+ var .dims != current_index_variable .dims ):
143+ raise ValueError (
144+ "dimension mismatch between %r %s and %r %s"
145+ % (dim , current_index_variable .dims , n , var .dims ))
146+
139147 if current_index_variable is not None and append :
140148 current_index = current_index_variable .to_index ()
141149 if isinstance (current_index , pd .MultiIndex ):
@@ -148,20 +156,19 @@ def merge_indexes(
148156 labels .append (cat .codes )
149157 levels .append (cat .categories )
150158
151- for n in var_names :
152- names .append (n )
153- var = variables [n ]
154- if ((current_index_variable is not None ) and
155- (var .dims != current_index_variable .dims )):
156- raise ValueError (
157- "dimension mismatch between %r %s and %r %s"
158- % (dim , current_index_variable .dims , n , var .dims ))
159- else :
159+ if not len (names ) and len (var_names ) == 1 :
160+ idx = pd .Index (variables [var_names [0 ]].values )
161+
162+ else :
163+ for n in var_names :
164+ names .append (n )
165+ var = variables [n ]
160166 cat = pd .Categorical (var .values , ordered = True )
161167 labels .append (cat .codes )
162168 levels .append (cat .categories )
163169
164- idx = pd .MultiIndex (labels = labels , levels = levels , names = names )
170+ idx = pd .MultiIndex (labels = labels , levels = levels , names = names )
171+
165172 vars_to_replace [dim ] = IndexVariable (dim , idx )
166173 vars_to_remove .extend (var_names )
167174
0 commit comments