<h4 dir="auto">Code Sample</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content=" def test_groupby_aggregate_item_by_item(self):
        def test_df():
            s = pd.DataFrame(np.array([[13, 14, 15, 16]]),
                             index=[0],
                             columns=['b', 'c', 'd', 'e'])
            num = np.array([[s, s, s, datetime.strptime('2016-12-28', &quot;%Y-%m-%d&quot;), 'asdf', 24],
                            [s, s, s, datetime.strptime('2016-12-28', &quot;%Y-%m-%d&quot;), 'asdf', 6]])
            columns = ['a', 'b', 'c', 'd', 'e', 'f']
            idx = [x for x in xrange(0, len(num))]
            return pd.DataFrame(num, index=idx, columns=columns)
        c = [test_df().sort_values(['d', 'e', 'f']),
             test_df().sort_values(['d', 'e', 'f'])]
        df = pd.concat(c)
        df = df[[&quot;e&quot;, &quot;a&quot;]].copy().reset_index(drop=True)
        df[&quot;e_idx&quot;] = df[&quot;e&quot;]
        what = [0, 0.5, 0.5, 1]

        def x():
            df.groupby([&quot;e_idx&quot;, &quot;e&quot;])[&quot;a&quot;].quantile(what)
        self.assertRaisesRegexp(ValueError,
                                &quot;'SeriesGroupBy' object has no attribute '_aggregate_item_by_item'&quot;,
                                x)"><pre class="notranslate"> <span class="pl-k">def</span> <span class="pl-en">test_groupby_aggregate_item_by_item</span>(<span class="pl-s1">self</span>):
        <span class="pl-k">def</span> <span class="pl-en">test_df</span>():
            <span class="pl-s1">s</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(<span class="pl-s1">np</span>.<span class="pl-en">array</span>([[<span class="pl-c1">13</span>, <span class="pl-c1">14</span>, <span class="pl-c1">15</span>, <span class="pl-c1">16</span>]]),
                             <span class="pl-s1">index</span><span class="pl-c1">=</span>[<span class="pl-c1">0</span>],
                             <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'b'</span>, <span class="pl-s">'c'</span>, <span class="pl-s">'d'</span>, <span class="pl-s">'e'</span>])
            <span class="pl-s1">num</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([[<span class="pl-s1">s</span>, <span class="pl-s1">s</span>, <span class="pl-s1">s</span>, <span class="pl-s1">datetime</span>.<span class="pl-en">strptime</span>(<span class="pl-s">'2016-12-28'</span>, <span class="pl-s">"%Y-%m-%d"</span>), <span class="pl-s">'asdf'</span>, <span class="pl-c1">24</span>],
                            [<span class="pl-s1">s</span>, <span class="pl-s1">s</span>, <span class="pl-s1">s</span>, <span class="pl-s1">datetime</span>.<span class="pl-en">strptime</span>(<span class="pl-s">'2016-12-28'</span>, <span class="pl-s">"%Y-%m-%d"</span>), <span class="pl-s">'asdf'</span>, <span class="pl-c1">6</span>]])
            <span class="pl-s1">columns</span> <span class="pl-c1">=</span> [<span class="pl-s">'a'</span>, <span class="pl-s">'b'</span>, <span class="pl-s">'c'</span>, <span class="pl-s">'d'</span>, <span class="pl-s">'e'</span>, <span class="pl-s">'f'</span>]
            <span class="pl-s1">idx</span> <span class="pl-c1">=</span> [<span class="pl-s1">x</span> <span class="pl-k">for</span> <span class="pl-s1">x</span> <span class="pl-c1">in</span> <span class="pl-en">xrange</span>(<span class="pl-c1">0</span>, <span class="pl-en">len</span>(<span class="pl-s1">num</span>))]
            <span class="pl-k">return</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(<span class="pl-s1">num</span>, <span class="pl-s1">index</span><span class="pl-c1">=</span><span class="pl-s1">idx</span>, <span class="pl-s1">columns</span><span class="pl-c1">=</span><span class="pl-s1">columns</span>)
        <span class="pl-s1">c</span> <span class="pl-c1">=</span> [<span class="pl-en">test_df</span>().<span class="pl-en">sort_values</span>([<span class="pl-s">'d'</span>, <span class="pl-s">'e'</span>, <span class="pl-s">'f'</span>]),
             <span class="pl-en">test_df</span>().<span class="pl-en">sort_values</span>([<span class="pl-s">'d'</span>, <span class="pl-s">'e'</span>, <span class="pl-s">'f'</span>])]
        <span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">concat</span>(<span class="pl-s1">c</span>)
        <span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">df</span>[[<span class="pl-s">"e"</span>, <span class="pl-s">"a"</span>]].<span class="pl-en">copy</span>().<span class="pl-en">reset_index</span>(<span class="pl-s1">drop</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
        <span class="pl-s1">df</span>[<span class="pl-s">"e_idx"</span>] <span class="pl-c1">=</span> <span class="pl-s1">df</span>[<span class="pl-s">"e"</span>]
        <span class="pl-s1">what</span> <span class="pl-c1">=</span> [<span class="pl-c1">0</span>, <span class="pl-c1">0.5</span>, <span class="pl-c1">0.5</span>, <span class="pl-c1">1</span>]

        <span class="pl-k">def</span> <span class="pl-en">x</span>():
            <span class="pl-s1">df</span>.<span class="pl-en">groupby</span>([<span class="pl-s">"e_idx"</span>, <span class="pl-s">"e"</span>])[<span class="pl-s">"a"</span>].<span class="pl-en">quantile</span>(<span class="pl-s1">what</span>)
        <span class="pl-s1">self</span>.<span class="pl-en">assertRaisesRegexp</span>(<span class="pl-v">ValueError</span>,
                                <span class="pl-s">"'SeriesGroupBy' object has no attribute '_aggregate_item_by_item'"</span>,
                                <span class="pl-s1">x</span>)</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">The return message from the ValueError in _GroupBy._aggregate_item_by_item is vague.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="                except (AttributeError):
&gt;                   raise ValueError
E                   ValueError

core/groupby.py:592: ValueError"><pre class="notranslate"><code class="notranslate">                except (AttributeError):
&gt;                   raise ValueError
E                   ValueError

core/groupby.py:592: ValueError
</code></pre></div>
<p dir="auto">The proposed change raises the error message for the user to see.</p>
<h4 dir="auto">Expected Output</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="                except (AttributeError) as e:
&gt;                   raise ValueError(e)
E                   ValueError: 'SeriesGroupBy' object has no attribute '_aggregate_item_by_item'

core/groupby.py:592: ValueError"><pre class="notranslate"><code class="notranslate">                except (AttributeError) as e:
&gt;                   raise ValueError(e)
E                   ValueError: 'SeriesGroupBy' object has no attribute '_aggregate_item_by_item'

core/groupby.py:592: ValueError
</code></pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
INSTALLED VERSIONS
------------------
commit: <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/pandas-dev/pandas/commit/b895968a90c918709b01b49db427f9b5ab28c1fe/hovercard" href="https://github.com/pandas-dev/pandas/commit/b895968a90c918709b01b49db427f9b5ab28c1fe"><tt>b895968</tt></a>
python: 2.7.11.final.0
python-bits: 64
OS: Darwin
OS-release: 15.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None
<p dir="auto">pandas: 0.19.0+311.gb895968.dirty<br>
nose: 1.3.7<br>
pip: 9.0.1<br>
setuptools: 32.3.1<br>
Cython: 0.25.2<br>
numpy: 1.11.3<br>
scipy: 0.18.1<br>
statsmodels: None<br>
xarray: None<br>
IPython: None<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.6.0<br>
pytz: 2016.10<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: None<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: None<br>
httplib2: None<br>
apiclient: None<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: None<br>
s3fs: None<br>
pandas_datareader: None</p>
</details>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [19]: df = DataFrame({'a':['A1', 'A1', 'A1'], 'b':['B1','B1','B2'], 'c':1})

In [20]: df.set_index('a').groupby('b').rank(method='first')
Out[20]: 
    c
a    
A1  1
A1  2
A1  1

In [21]: df.set_index('a').groupby('c').rank(method='first')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
&lt;ipython-input-21-6b8d4cae9d91&gt; in &lt;module&gt;()
----&gt; 1 df.set_index('a').groupby('c').rank(method='first')

/home/nicolas/Git/pandas/pandas/core/groupby.pyc in rank(self, axis, numeric_only, method, na_option, ascending, pct)

/home/nicolas/Git/pandas/pandas/core/groupby.pyc in wrapper(*args, **kwargs)
    618                     # mark this column as an error
    619                     try:
--&gt; 620                         return self._aggregate_item_by_item(name, *args, **kwargs)
    621                     except (AttributeError):
    622                         raise ValueError

/home/nicolas/Git/pandas/pandas/core/groupby.pyc in _aggregate_item_by_item(self, func, *args, **kwargs)
   3076             # GH6337
   3077             if not len(result_columns) and errors is not None:
-&gt; 3078                 raise errors
   3079 
   3080         return DataFrame(result, columns=result_columns)

TypeError: rank() got an unexpected keyword argument 'numeric_only'"><pre class="notranslate"><code class="notranslate">In [19]: df = DataFrame({'a':['A1', 'A1', 'A1'], 'b':['B1','B1','B2'], 'c':1})

In [20]: df.set_index('a').groupby('b').rank(method='first')
Out[20]: 
    c
a    
A1  1
A1  2
A1  1

In [21]: df.set_index('a').groupby('c').rank(method='first')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
&lt;ipython-input-21-6b8d4cae9d91&gt; in &lt;module&gt;()
----&gt; 1 df.set_index('a').groupby('c').rank(method='first')

/home/nicolas/Git/pandas/pandas/core/groupby.pyc in rank(self, axis, numeric_only, method, na_option, ascending, pct)

/home/nicolas/Git/pandas/pandas/core/groupby.pyc in wrapper(*args, **kwargs)
    618                     # mark this column as an error
    619                     try:
--&gt; 620                         return self._aggregate_item_by_item(name, *args, **kwargs)
    621                     except (AttributeError):
    622                         raise ValueError

/home/nicolas/Git/pandas/pandas/core/groupby.pyc in _aggregate_item_by_item(self, func, *args, **kwargs)
   3076             # GH6337
   3077             if not len(result_columns) and errors is not None:
-&gt; 3078                 raise errors
   3079 
   3080         return DataFrame(result, columns=result_columns)

TypeError: rank() got an unexpected keyword argument 'numeric_only'
</code></pre></div>
<p dir="auto">I'm trying to obtain what I would get with a <code class="notranslate">row_number()</code> in SQL...</p>
<p dir="auto">Notice that if I replace the value in the <code class="notranslate">'c'</code> column with the string <code class="notranslate">'1'</code>, then even <code class="notranslate">df.set_index('a').groupby('b').rank(method='first')</code> fails.</p>
<p dir="auto">Am I doing something wrong?</p>