Repository: dask/dask

Issue:
BUG: specifiy a numeric column breaking in groupbys
```
In [19]: dask.__version__
Out[19]: '0.12.0+42.g0d677ef'

In [1]: import dask.dataframe as dd

In [13]: df = pd.DataFrame({'A' : ['foo', 'foo', 'bar'], 0: [1,2,3]})

In [14]: ddf = dd.from_pandas(df, npartitions=3)

In [15]: ddf.groupby(df.A).sum(split_out=3).compute()
Out[15]:
     0
A
foo  3
bar  3

In [16]: ddf.groupby(df.A)[0].sum(split_out=3).compute()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-16-c2457942763e> in <module>()
----> 1 ddf.groupby(df.A)[0].sum(split_out=3).compute()

C:\Anaconda\envs\bmc3-dev\lib\site-packages\dask\base.py in compute(self, **kwargs)
     76             Extra keywords to forward to the scheduler ``get`` function.
     77         """
---> 78         return compute(self, **kwargs)[0]
     79
     80     @classmethod

C:\Anaconda\envs\bmc3-dev\lib\site-packages\dask\base.py in compute(*args, **kwargs)
    176         dsk = merge(var.dask for var in variables)
    177     keys = [var._keys() for var in variables]
--> 178     results = get(dsk, keys, **kwargs)
    179
    180     results_iter = iter(results)

C:\Anaconda\envs\bmc3-dev\lib\site-packages\dask\threaded.py in get(dsk, result, cache, num_workers, **kwargs)
     74     results = get_async(pool.apply_async, len(pool._pool), dsk, result,
     75                         cache=cache, get_id=_thread_get_id,
---> 76                         **kwargs)
     77
     78     # Cleanup pools associated to dead threads

C:\Anaconda\envs\bmc3-dev\lib\site-packages\dask\async.py in get_async(apply_async, num_workers, dsk, result, cache, get_id, raise_on_exception, rerun_exceptions_locally, callbacks, dumps, loads, **kwargs)
    491                     _execute_task(task, data)  # Re-execute locally
    492                 else:
--> 493                     raise(remote_exception(res, tb))
    494             state['cache'][key] = res
    495             finish_task(dsk, key, state, results, keyorder.get)

TypeError: 'int' object is not iterable

Traceback
---------
  File "C:\Anaconda\envs\bmc3-dev\lib\site-packages\dask\async.py", line 268, in execute_task
    result = _execute_task(task, data)
  File "C:\Anaconda\envs\bmc3-dev\lib\site-packages\dask\async.py", line 249, in _execute_task
    return func(*args2)
  File "C:\Anaconda\envs\bmc3-dev\lib\site-packages\dask\compatibility.py", line 47, in apply
    return func(*args, **kwargs)
  File "C:\Anaconda\envs\bmc3-dev\lib\site-packages\dask\dataframe\groupby.py", line 134, in _apply_chunk
    columns = columns if isinstance(columns, str) else list(columns)


In [17]: ddf.groupby(df.A)[[0]].sum(split_out=3).compute()
Out[17]:
     0
A
foo  3
bar  3

```


Discussion:
any update on this issue?

Resolving patch:
diff --git a/dask/dataframe/groupby.py b/dask/dataframe/groupby.py
--- a/dask/dataframe/groupby.py
+++ b/dask/dataframe/groupby.py
@@ -86,7 +86,8 @@ def _maybe_slice(grouped, columns):
     """
     if isinstance(grouped, pd.core.groupby.DataFrameGroupBy):
         if columns is not None:
-            columns = columns if isinstance(columns, str) else list(columns)
+            if isinstance(columns, (tuple, list, set, pd.Index)):
+                columns = list(columns)
             return grouped[columns]
     return grouped
 
@@ -131,7 +132,8 @@ def _apply_chunk(df, *index, **kwargs):
     if isinstance(df, pd.Series) or columns is None:
         return func(df.groupby(index))
     else:
-        columns = columns if isinstance(columns, str) else list(columns)
+        if isinstance(columns, (tuple, list, set, pd.Index)):
+            columns = list(columns)
         return func(df.groupby(index)[columns])
 
 


Test patch:
diff --git a/dask/dataframe/tests/test_groupby.py b/dask/dataframe/tests/test_groupby.py
--- a/dask/dataframe/tests/test_groupby.py
+++ b/dask/dataframe/tests/test_groupby.py
@@ -963,3 +963,11 @@ def test_split_out_multi_column_groupby():
     expected = df.groupby(['x', 'y']).z.mean()
 
     assert_eq(result, expected, check_dtype=False)
+
+
+def test_groupby_numeric_column():
+    df = pd.DataFrame({'A' : ['foo', 'foo', 'bar'], 0: [1,2,3]})
+    ddf = dd.from_pandas(df, npartitions=3)
+
+    assert_eq(ddf.groupby(ddf.A)[0].sum(),
+              df.groupby(df.A)[0].sum())