Weird behaviour with groupby on ordered categorical columns : <p>MCVE</p>

<pre><code>df = pd.DataFrame({
    'Cat': ['SF', 'W', 'F', 'R64', 'SF', 'F'], 
    'ID': [1, 1, 1, 2, 2, 2]
})

df.Cat = pd.Categorical(
    df.Cat, categories=['R64', 'SF', 'F', 'W'], ordered=True)
</code></pre>

<p></p>

<p>As you can see, I've define an ordered categorical column on <code>Cat</code>. To verify, check;</p>

<pre><code>0     SF
1      W
2      F
3    R64
4     SF
5      F
Name: Cat, dtype: category
Categories (4, object): [R64 &lt; SF &lt; F &lt; W]
</code></pre>

<p>I want to find the largest category PER ID. Doing <code>groupby</code> + <code>max</code> works.</p>

<pre><code>df.groupby('ID').Cat.max()

ID
1    W
2    F
Name: Cat, dtype: object
</code></pre>

<p>But I don't want ID to be the index, so I specify <code>as_index=False</code>.</p>

<pre><code>df.groupby('ID', as_index=False).Cat.max()

   ID Cat
0   1   W
1   2  SF
</code></pre>

<p>Oops! Now, the max is taken <strong>lexicographically</strong>. Can anyone explain whether this is intended behaviour? Or is this a bug?</p>

<p>Note, for this problem, the workaround is <code>df.groupby('ID').Cat.max().reset_index()</code>.</p>

<p>Note, </p>

<pre><code>&gt;&gt;&gt; pd.__version__
'0.22.0'
</code></pre>
