<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd

df = pd.DataFrame(data=[1,2,3,3,3,3,4,4,4,5,5,5], columns=['abc'], ).sort_values('abc')
df['Rank'] = df['abc'].rank(method='dense')
df['Rank_Pct']= df['abc'].rank(pct=True, method='dense', )
df['Rank_Pct_Manual']= df['Rank'] / df['Rank'].max()

df.head()"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>

<span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(<span class="pl-s1">data</span><span class="pl-c1">=</span>[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>,<span class="pl-c1">3</span>,<span class="pl-c1">3</span>,<span class="pl-c1">3</span>,<span class="pl-c1">4</span>,<span class="pl-c1">4</span>,<span class="pl-c1">4</span>,<span class="pl-c1">5</span>,<span class="pl-c1">5</span>,<span class="pl-c1">5</span>], <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'abc'</span>], ).<span class="pl-en">sort_values</span>(<span class="pl-s">'abc'</span>)
<span class="pl-s1">df</span>[<span class="pl-s">'Rank'</span>] <span class="pl-c1">=</span> <span class="pl-s1">df</span>[<span class="pl-s">'abc'</span>].<span class="pl-en">rank</span>(<span class="pl-s1">method</span><span class="pl-c1">=</span><span class="pl-s">'dense'</span>)
<span class="pl-s1">df</span>[<span class="pl-s">'Rank_Pct'</span>]<span class="pl-c1">=</span> <span class="pl-s1">df</span>[<span class="pl-s">'abc'</span>].<span class="pl-en">rank</span>(<span class="pl-s1">pct</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">method</span><span class="pl-c1">=</span><span class="pl-s">'dense'</span>, )
<span class="pl-s1">df</span>[<span class="pl-s">'Rank_Pct_Manual'</span>]<span class="pl-c1">=</span> <span class="pl-s1">df</span>[<span class="pl-s">'Rank'</span>] <span class="pl-c1">/</span> <span class="pl-s1">df</span>[<span class="pl-s">'Rank'</span>].<span class="pl-en">max</span>()

<span class="pl-s1">df</span>.<span class="pl-en">head</span>()</pre></div>
<p dir="auto">Output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    abc  Rank  Rank_Pct  Rank_Pct_Manual
0     1   1.0  0.083333              0.2
1     2   2.0  0.166667              0.4
2     3   3.0  0.250000              0.6
3     3   3.0  0.250000              0.6
4     3   3.0  0.250000              0.6
5     3   3.0  0.250000              0.6
6     4   4.0  0.333333              0.8
7     4   4.0  0.333333              0.8
8     4   4.0  0.333333              0.8
9     5   5.0  0.416667              1.0
10    5   5.0  0.416667              1.0
11    5   5.0  0.416667              1.0"><pre class="notranslate"><code class="notranslate">    abc  Rank  Rank_Pct  Rank_Pct_Manual
0     1   1.0  0.083333              0.2
1     2   2.0  0.166667              0.4
2     3   3.0  0.250000              0.6
3     3   3.0  0.250000              0.6
4     3   3.0  0.250000              0.6
5     3   3.0  0.250000              0.6
6     4   4.0  0.333333              0.8
7     4   4.0  0.333333              0.8
8     4   4.0  0.333333              0.8
9     5   5.0  0.416667              1.0
10    5   5.0  0.416667              1.0
11    5   5.0  0.416667              1.0
</code></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">If you chose both the <code class="notranslate">pct=True</code> and <code class="notranslate">method='dense'</code> options of <code class="notranslate">Series.rank</code>, you don't get the expected maximum percentile of 1 if there are repeated values in the <code class="notranslate">Series</code>. This is because the function (e.g., <code class="notranslate">rank_1d_float64()</code>) always divides by the total number of elements in the <code class="notranslate">Series</code>. But in the case of the <code class="notranslate">dense</code> method, we should divide by the maximum rank value.</p>
<p dir="auto">I'm working on a PR now.</p>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">I would expect the values of <code class="notranslate">Rank_Pct</code> and <code class="notranslate">Rank_Pct_Manual</code> to be the same, and that the maximum of both should be 1.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    abc  Rank  Rank_Pct  Rank_Pct_Manual
0     1   1.0       0.2              0.2
1     2   2.0       0.4              0.4
2     3   3.0       0.6              0.6
3     3   3.0       0.6              0.6
4     3   3.0       0.6              0.6
5     3   3.0       0.6              0.6
6     4   4.0       0.8              0.8
7     4   4.0       0.8              0.8
8     4   4.0       0.8              0.8
9     5   5.0       1.0              1.0
10    5   5.0       1.0              1.0
11    5   5.0       1.0              1.0"><pre class="notranslate"><code class="notranslate">    abc  Rank  Rank_Pct  Rank_Pct_Manual
0     1   1.0       0.2              0.2
1     2   2.0       0.4              0.4
2     3   3.0       0.6              0.6
3     3   3.0       0.6              0.6
4     3   3.0       0.6              0.6
5     3   3.0       0.6              0.6
6     4   4.0       0.8              0.8
7     4   4.0       0.8              0.8
8     4   4.0       0.8              0.8
9     5   5.0       1.0              1.0
10    5   5.0       1.0              1.0
11    5   5.0       1.0              1.0
</code></pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<p dir="auto">commit: None<br>
python: 3.6.3.final.0<br>
python-bits: 64<br>
OS: Darwin<br>
OS-release: 16.7.0<br>
machine: x86_64<br>
processor: i386<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: en_US.UTF-8<br>
LOCALE: en_US.UTF-8</p>
<p dir="auto">pandas: 0.21.0<br>
pytest: 3.2.3<br>
pip: 9.0.1<br>
setuptools: 36.3.0<br>
Cython: None<br>
numpy: 1.13.3<br>
scipy: 0.19.1<br>
pyarrow: 0.7.1<br>
xarray: None<br>
IPython: 6.2.1<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.6.1<br>
pytz: 2017.3<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: 2.0.2<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: 0.999999999<br>
sqlalchemy: 1.1.15<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.9.6<br>
s3fs: None<br>
fastparquet: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">I find the behavior of rank function with method = 'dense' and pct = True unexpected as it looks like, in order to calculate percentile ranks, the function is using the total number of observations instead of the number of <em>distinct</em> observations.</p>
<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import pandas as pd
n_rep = 2
ts = pd.Series([1,2,3,4] * n_rep )
output = ts.rank(method = 'dense', pct = True)"><pre class="notranslate"><code class="notranslate">import pandas as pd
n_rep = 2
ts = pd.Series([1,2,3,4] * n_rep )
output = ts.rank(method = 'dense', pct = True)
</code></pre></div>
<h4 dir="auto">Problem description</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ts.rank(method = 'dense', pct = True)
Out[116]: 
0    0.125
1    0.250
2    0.375
3    0.500
4    0.125
5    0.250
6    0.375
7    0.500"><pre class="notranslate"><code class="notranslate">ts.rank(method = 'dense', pct = True)
Out[116]: 
0    0.125
1    0.250
2    0.375
3    0.500
4    0.125
5    0.250
6    0.375
7    0.500
</code></pre></div>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">Something similar to:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="pd.Series([1,2,3,4] * 2).rank(method = 'dense', pct = True) * n_rep 
Out[118]: 
0    0.25
1    0.50
2    0.75
3    1.00
4    0.25
5    0.50
6    0.75
7    1.00"><pre class="notranslate"><code class="notranslate">pd.Series([1,2,3,4] * 2).rank(method = 'dense', pct = True) * n_rep 
Out[118]: 
0    0.25
1    0.50
2    0.75
3    1.00
4    0.25
5    0.50
6    0.75
7    1.00
</code></pre></div>
<p dir="auto">Also, I would expected the result above to be invariant to n_rep.<br>
i.e. I would expect a "mapping" {value -&gt; pct_rank} that would not depend on how many times the value is repeated, while it is not the case here.</p>