@@ -1312,9 +1312,8 @@ def reindex(self, axes_to_reindex=None, new_axis=None, fill_value=np.nan, inplac
13121312 axes_to_reindex : axis ref or dict {axis ref: axis} or list of tuple (axis ref, axis) \
13131313 or list of Axis or AxisCollection
13141314 Axes to reindex. If a single axis reference is given, the `new_axis` argument must be provided.
1315- If a list of Axis or an AxisCollection is given, all axes will be reindexed by the new ones.
1316- In that case, the number of new axes must match the number of the old ones.
1317- new_axis : int, str, list/tuple/array of str or Axis, optional
1315+ If a list of Axis or an AxisCollection is given, existing axes are reindexed while missing ones are added.
1316+ new_axis : int, str, list/tuple/array of str, Group or Axis, optional
13181317 List of new labels or new axis if `axes_to_replace` contains a single axis reference.
13191318 fill_value : scalar or LArray, optional
13201319 Value used to fill cells corresponding to label combinations which were not present before reindexing.
@@ -1342,58 +1341,70 @@ def reindex(self, axes_to_reindex=None, new_axis=None, fill_value=np.nan, inplac
13421341 a\\ b b0 b1
13431342 a0 0 1
13441343 a1 2 3
1344+ >>> arr2 = ndrange('a=a1,a2;c=c0;b=b2..b0')
1345+ >>> arr2
1346+ a c\\ b b2 b1 b0
1347+ a1 c0 0 1 2
1348+ a2 c0 3 4 5
13451349
1346- Reindex one axis
1350+ Reindex an axis by passing labels (list or string)
13471351
1348- >>> arr.reindex(X.b , ['b1', 'b2', 'b0'], fill_value=-1 )
1349- a\\ b b1 b2 b0
1350- a0 1 -1 0
1351- a1 3 -1 2
1352- >>> arr.reindex(X.b , 'b0..b2', fill_value=-1)
1352+ >>> arr.reindex('b' , ['b1', 'b2', 'b0'])
1353+ a\\ b b1 b2 b0
1354+ a0 1.0 nan 0. 0
1355+ a1 3.0 nan 2.0
1356+ >>> arr.reindex('b' , 'b0..b2', fill_value=-1)
13531357 a\\ b b0 b1 b2
13541358 a0 0 1 -1
13551359 a1 2 3 -1
13561360
1357- Reindex several axes
1361+ Reindex using an axis from another array
13581362
1359- >>> a = Axis(['a1', 'a2', 'a0'], 'a')
1360- >>> b = Axis(['b2', 'b1', 'b0'], 'b')
1361- >>> arr.reindex({'a': a, 'b': b}, fill_value=-1)
1363+ >>> arr.reindex('b', arr2.b, fill_value=-1)
13621364 a\\ b b2 b1 b0
1363- a1 -1 3 2
1364- a2 -1 -1 -1
13651365 a0 -1 1 0
1366- >>> arr.reindex({X.a: a, X.b: b})
1367- a\\ b b2 b1 b0
1368- a1 nan 3.0 2.0
1369- a2 nan nan nan
1370- a0 nan 1.0 0.0
1366+ a1 -1 3 2
13711367
1372- Reindex using axes from another array
1368+ Reindex using a subset of an axis
13731369
1374- >>> arr2 = ndrange('a=a0,a1;c=c0..c0;b=b0..b2')
1375- >>> arr2
1376- a c\\ b b0 b1 b2
1377- a0 c0 0 1 2
1378- a1 c0 3 4 5
1379- >>> arr.reindex(arr2.axes)
1380- a b\\ c c0
1381- a0 b0 0.0
1382- a0 b1 1.0
1383- a0 b2 nan
1384- a1 b0 2.0
1385- a1 b1 3.0
1386- a1 b2 nan
1387- >>> arr2.reindex(arr.axes)
1388- a c\\ b b0 b1
1389- a0 c0 0.0 1.0
1390- a1 c0 3.0 4.0
1370+ >>> arr.reindex('b', arr2.b['b1':], fill_value=-1)
1371+ a\\ b b1 b0
1372+ a0 1 0
1373+ a1 3 2
1374+
1375+ Reindex several axes
1376+
1377+ >>> arr.reindex({'a': arr2.a, 'b': arr2.b}, fill_value=-1)
1378+ a\\ b b2 b1 b0
1379+ a1 -1 3 2
1380+ a2 -1 -1 -1
1381+ >>> arr.reindex({'a': arr2.a, 'b': arr2.b['b1':]}, fill_value=-1)
1382+ a\\ b b1 b0
1383+ a1 3 2
1384+ a2 -1 -1
1385+
1386+ Reindex by passing a collection of axes
1387+
1388+ >>> arr.reindex(arr2.axes, fill_value=-1)
1389+ a b\\ c c0
1390+ a1 b2 -1
1391+ a1 b1 3
1392+ a1 b0 2
1393+ a2 b2 -1
1394+ a2 b1 -1
1395+ a2 b0 -1
1396+ >>> arr2.reindex(arr.axes, fill_value=-1)
1397+ a c\\ b b0 b1
1398+ a0 c0 -1 -1
1399+ a1 c0 2 1
13911400 """
13921401 # XXX: can't we move this to AxisCollection.replace?
1393- if isinstance ( new_axis , ( int , basestring , list , tuple , np . ndarray ) ):
1402+ if new_axis is not None and not isinstance ( new_axis , Axis ):
13941403 new_axis = Axis (new_axis , self .axes [axes_to_reindex ].name )
1395- if isinstance (new_axis , Axis ):
1404+ elif isinstance (new_axis , Axis ):
13961405 new_axis = new_axis .rename (self .axes [axes_to_reindex ].name )
1406+ if isinstance (axes_to_reindex , (list , tuple )) and all ([isinstance (axis , Axis ) for axis in axes_to_reindex ]):
1407+ axes_to_reindex = AxisCollection (axes_to_reindex )
13971408 if isinstance (axes_to_reindex , AxisCollection ):
13981409 assert new_axis is None
13991410 # add extra axes if needed
0 commit comments