Repository: pandas-dev/pandas

Issue:
ENH: add rank option to DataFrame for consistency with Series
related #5971



Discussion:
This is easy enough


Resolving patch:
diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py
--- a/pandas/core/algorithms.py
+++ b/pandas/core/algorithms.py
@@ -277,7 +277,7 @@ def rank(values, axis=0, method='average', na_option='keep',
     elif values.ndim == 2:
         f, values = _get_data_algo(values, _rank2d_functions)
         ranks = f(values, axis=axis, ties_method=method,
-                  ascending=ascending, na_option=na_option)
+                  ascending=ascending, na_option=na_option, pct=pct)
 
     return ranks
 
diff --git a/pandas/core/frame.py b/pandas/core/frame.py
--- a/pandas/core/frame.py
+++ b/pandas/core/frame.py
@@ -4182,7 +4182,7 @@ def f(arr):
         return data.apply(f, axis=axis)
 
     def rank(self, axis=0, numeric_only=None, method='average',
-             na_option='keep', ascending=True):
+             na_option='keep', ascending=True, pct=False):
         """
         Compute numerical data ranks (1 through n) along axis. Equal values are
         assigned a rank that is the average of the ranks of those values
@@ -4205,6 +4205,8 @@ def rank(self, axis=0, numeric_only=None, method='average',
             * bottom: smallest rank if descending
         ascending : boolean, default True
             False for ranks by high (1) to low (N)
+        pct : boolean, default False
+            Computes percentage rank of data
 
         Returns
         -------
@@ -4214,18 +4216,18 @@ def rank(self, axis=0, numeric_only=None, method='average',
         if numeric_only is None:
             try:
                 ranks = algos.rank(self.values, axis=axis, method=method,
-                                   ascending=ascending, na_option=na_option)
+                                   ascending=ascending, na_option=na_option,
+                                   pct=pct)
                 return self._constructor(ranks, index=self.index,
                                          columns=self.columns)
             except TypeError:
                 numeric_only = True
-
         if numeric_only:
             data = self._get_numeric_data()
         else:
             data = self
         ranks = algos.rank(data.values, axis=axis, method=method,
-                           ascending=ascending, na_option=na_option)
+                           ascending=ascending, na_option=na_option, pct=pct)
         return self._constructor(ranks, index=data.index, columns=data.columns)
 
     def to_timestamp(self, freq=None, how='start', axis=0, copy=True):
diff --git a/pandas/core/series.py b/pandas/core/series.py
--- a/pandas/core/series.py
+++ b/pandas/core/series.py
@@ -1732,7 +1732,7 @@ def rank(self, method='average', na_option='keep', ascending=True,
             keep: leave NA values where they are
         ascending : boolean, default True
             False for ranks by high (1) to low (N)
-        pct : boolean, defeault False
+        pct : boolean, default False
             Computes percentage rank of data
 
         Returns


Test patch:
diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py
--- a/pandas/tests/test_frame.py
+++ b/pandas/tests/test_frame.py
@@ -10933,12 +10933,24 @@ def test_rank(self):
 
     def test_rank2(self):
         from datetime import datetime
+        df = DataFrame([[1, 3, 2], [1, 2, 3]])
+        expected = DataFrame([[1.0, 3.0, 2.0], [1, 2, 3]]) / 3.0
+        result = df.rank(1, pct=True)
+        assert_frame_equal(result, expected)
+        
+        df = DataFrame([[1, 3, 2], [1, 2, 3]])
+        expected = df.rank(0) / 2.0
+        result = df.rank(0, pct=True)
+        assert_frame_equal(result, expected)
+
+
 
         df = DataFrame([['b', 'c', 'a'], ['a', 'c', 'b']])
         expected = DataFrame([[2.0, 3.0, 1.0], [1, 3, 2]])
         result = df.rank(1, numeric_only=False)
         assert_frame_equal(result, expected)
 
+        
         expected = DataFrame([[2.0, 1.5, 1.0], [1, 1.5, 2]])
         result = df.rank(0, numeric_only=False)
         assert_frame_equal(result, expected)