Repository: pandas-dev/pandas

Issue:
DOC: Cookbook example on reading CSV by chunking gives error
URL linked in the cookbook: http://stackoverflow.com/questions/11622652/large-persistent-dataframe-in-pandas/12193309#12193309

Traceback:

``` python
  File "/usr/local/lib/python2.7/dist-packages/pandas/tools/merge.py", line 929, in concat
    verify_integrity=verify_integrity)
  File "/usr/local/lib/python2.7/dist-packages/pandas/tools/merge.py", line 944, in __init__
    '"{0}"'.format(type(objs).__name__))
AssertionError: first argument must be a list-like of pandas objects, you passed an object of type "TextFileReader"
```

To be precise: Concatenation does not work in this example.



Discussion:
what version pandas?

0.13.1

want to submit a PR for this?

I think you can add a check for `__iter__` where this assertionerror happens; but that might be too loose a check (IIRC this checks types very explicity)

@jreback : Sorry! Won't be able to do a PR. schedule is tight..

Maybe if you can update the Stack overflow answer on how to solve this, it may suffice? Like for version 0.13.1 this is how you do the same..


Resolving patch:
diff --git a/pandas/tools/merge.py b/pandas/tools/merge.py
--- a/pandas/tools/merge.py
+++ b/pandas/tools/merge.py
@@ -20,6 +20,7 @@
 from pandas.core.common import (PandasError, ABCSeries,
                                 is_timedelta64_dtype, is_datetime64_dtype,
                                 is_integer_dtype, isnull)
+from pandas.io.parsers import TextFileReader
 
 import pandas.core.common as com
 
@@ -938,10 +939,10 @@ class _Concatenator(object):
     def __init__(self, objs, axis=0, join='outer', join_axes=None,
                  keys=None, levels=None, names=None,
                  ignore_index=False, verify_integrity=False):
-        if not isinstance(objs, (list,tuple,types.GeneratorType,dict)):
-            raise AssertionError('first argument must be a list-like of pandas '
-                                 'objects, you passed an object of type '
-                                 '"{0}"'.format(type(objs).__name__))
+        if not isinstance(objs, (list,tuple,types.GeneratorType,dict,TextFileReader)):
+            raise TypeError('first argument must be a list-like of pandas '
+                            'objects, you passed an object of type '
+                            '"{0}"'.format(type(objs).__name__))
 
         if join == 'outer':
             self.intersect = False


Test patch:
diff --git a/pandas/tools/tests/test_merge.py b/pandas/tools/tests/test_merge.py
--- a/pandas/tools/tests/test_merge.py
+++ b/pandas/tools/tests/test_merge.py
@@ -16,7 +16,7 @@
                                  assert_almost_equal, rands,
                                  makeCustomDataframe as mkdf,
                                  assertRaisesRegexp)
-from pandas import isnull, DataFrame, Index, MultiIndex, Panel, Series, date_range, read_table
+from pandas import isnull, DataFrame, Index, MultiIndex, Panel, Series, date_range, read_table, read_csv
 import pandas.algos as algos
 import pandas.util.testing as tm
 
@@ -2048,11 +2048,27 @@ def test_concat_invalid(self):
     def test_concat_invalid_first_argument(self):
         df1 = mkdf(10, 2)
         df2 = mkdf(10, 2)
-        self.assertRaises(AssertionError, concat, df1, df2)
+        self.assertRaises(TypeError, concat, df1, df2)
 
         # generator ok though
         concat(DataFrame(np.random.rand(5,5)) for _ in range(3))
 
+        # text reader ok
+        # GH6583
+        data = """index,A,B,C,D
+foo,2,3,4,5
+bar,7,8,9,10
+baz,12,13,14,15
+qux,12,13,14,15
+foo2,12,13,14,15
+bar2,12,13,14,15
+"""
+
+        reader = read_csv(StringIO(data), chunksize=1)
+        result = concat(reader, ignore_index=True)
+        expected = read_csv(StringIO(data))
+        assert_frame_equal(result,expected)
+
 class TestOrderedMerge(tm.TestCase):
 
     def setUp(self):