Skip to content

Commit 238fbd1

Browse files
jrebackjeffreystarr
authored andcommitted
API: change AssertionError to TypeError for invalid types passed to concat (GH6583)
REGR: TextFileReader in concat, which was affecting a common user idiom (GH6583)
1 parent 0f8e421 commit 238fbd1

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

pandas/tools/merge.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from pandas.core.common import (PandasError, ABCSeries,
2121
is_timedelta64_dtype, is_datetime64_dtype,
2222
is_integer_dtype, isnull)
23+
from pandas.io.parsers import TextFileReader
2324

2425
import pandas.core.common as com
2526

@@ -938,10 +939,10 @@ class _Concatenator(object):
938939
def __init__(self, objs, axis=0, join='outer', join_axes=None,
939940
keys=None, levels=None, names=None,
940941
ignore_index=False, verify_integrity=False):
941-
if not isinstance(objs, (list,tuple,types.GeneratorType,dict)):
942-
raise AssertionError('first argument must be a list-like of pandas '
943-
'objects, you passed an object of type '
944-
'"{0}"'.format(type(objs).__name__))
942+
if not isinstance(objs, (list,tuple,types.GeneratorType,dict,TextFileReader)):
943+
raise TypeError('first argument must be a list-like of pandas '
944+
'objects, you passed an object of type '
945+
'"{0}"'.format(type(objs).__name__))
945946

946947
if join == 'outer':
947948
self.intersect = False

pandas/tools/tests/test_merge.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
assert_almost_equal, rands,
1717
makeCustomDataframe as mkdf,
1818
assertRaisesRegexp)
19-
from pandas import isnull, DataFrame, Index, MultiIndex, Panel, Series, date_range, read_table
19+
from pandas import isnull, DataFrame, Index, MultiIndex, Panel, Series, date_range, read_table, read_csv
2020
import pandas.algos as algos
2121
import pandas.util.testing as tm
2222

@@ -2048,11 +2048,27 @@ def test_concat_invalid(self):
20482048
def test_concat_invalid_first_argument(self):
20492049
df1 = mkdf(10, 2)
20502050
df2 = mkdf(10, 2)
2051-
self.assertRaises(AssertionError, concat, df1, df2)
2051+
self.assertRaises(TypeError, concat, df1, df2)
20522052

20532053
# generator ok though
20542054
concat(DataFrame(np.random.rand(5,5)) for _ in range(3))
20552055

2056+
# text reader ok
2057+
# GH6583
2058+
data = """index,A,B,C,D
2059+
foo,2,3,4,5
2060+
bar,7,8,9,10
2061+
baz,12,13,14,15
2062+
qux,12,13,14,15
2063+
foo2,12,13,14,15
2064+
bar2,12,13,14,15
2065+
"""
2066+
2067+
reader = read_csv(StringIO(data), chunksize=1)
2068+
result = concat(reader, ignore_index=True)
2069+
expected = read_csv(StringIO(data))
2070+
assert_frame_equal(result,expected)
2071+
20562072
class TestOrderedMerge(tm.TestCase):
20572073

20582074
def setUp(self):

0 commit comments

Comments
 (0)