@@ -2530,7 +2530,7 @@ def _m8_to_i8(x):
2530
2530
#----------------------------------------------------------------------
2531
2531
# Sorting
2532
2532
2533
- def sort (self , columns = None , column = None , axis = 0 , ascending = True ,
2533
+ def sort (self , columns = None , axis = 0 , ascending = True ,
2534
2534
inplace = False ):
2535
2535
"""
2536
2536
Sort DataFrame either by labels (along either axis) or by the values in
@@ -2539,8 +2539,9 @@ def sort(self, columns=None, column=None, axis=0, ascending=True,
2539
2539
Parameters
2540
2540
----------
2541
2541
columns : object
2542
- Column name(s) in frame. Accepts a column name or a list or tuple
2543
- for a nested sort.
2542
+ Column name(s) in frame. Accepts a column name or a list
2543
+ for a nested sort. A tuple will be interpreted as the
2544
+ levels of a multi-index.
2544
2545
ascending : boolean or list, default True
2545
2546
Sort ascending vs. descending. Specify list for multiple sort
2546
2547
orders
@@ -2557,9 +2558,6 @@ def sort(self, columns=None, column=None, axis=0, ascending=True,
2557
2558
-------
2558
2559
sorted : DataFrame
2559
2560
"""
2560
- if column is not None : # pragma: no cover
2561
- warnings .warn ("column is deprecated, use columns" , FutureWarning )
2562
- columns = column
2563
2561
return self .sort_index (by = columns , axis = axis , ascending = ascending ,
2564
2562
inplace = inplace )
2565
2563
@@ -2574,8 +2572,9 @@ def sort_index(self, axis=0, by=None, ascending=True, inplace=False,
2574
2572
axis : {0, 1}
2575
2573
Sort index/rows versus columns
2576
2574
by : object
2577
- Column name(s) in frame. Accepts a column name or a list or tuple
2578
- for a nested sort.
2575
+ Column name(s) in frame. Accepts a column name or a list
2576
+ for a nested sort. A tuple will be interpreted as the
2577
+ levels of a multi-index.
2579
2578
ascending : boolean or list, default True
2580
2579
Sort ascending vs. descending. Specify list for multiple sort
2581
2580
orders
@@ -2602,7 +2601,7 @@ def sort_index(self, axis=0, by=None, ascending=True, inplace=False,
2602
2601
if axis != 0 :
2603
2602
raise ValueError ('When sorting by column, axis must be 0 '
2604
2603
'(rows)' )
2605
- if not isinstance (by , ( tuple , list ) ):
2604
+ if not isinstance (by , list ):
2606
2605
by = [by ]
2607
2606
if com ._is_sequence (ascending ) and len (by ) != len (ascending ):
2608
2607
raise ValueError ('Length of ascending (%d) != length of by'
@@ -2629,6 +2628,13 @@ def trans(v):
2629
2628
by = by [0 ]
2630
2629
k = self [by ].values
2631
2630
if k .ndim == 2 :
2631
+
2632
+ # try to be helpful
2633
+ if isinstance (self .columns , MultiIndex ):
2634
+ raise ValueError ('Cannot sort by column %s in a multi-index'
2635
+ ' you need to explicity provide all the levels'
2636
+ % str (by ))
2637
+
2632
2638
raise ValueError ('Cannot sort by duplicate column %s'
2633
2639
% str (by ))
2634
2640
if isinstance (ascending , (tuple , list )):
0 commit comments