Skip to content

Commit 759a907

Browse files
committed
Merge pull request pandas-dev#6941 from jreback/concat
REGR/API: accept TextFileReader in concat (GH6583)
2 parents b8f56f2 + 5983c9c commit 759a907

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

doc/source/release.rst

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ API Changes
175175
- Replace ``pandas.compat.scipy.scoreatpercentile`` with ``numpy.percentile`` (:issue:`6810`)
176176
- ``.quantile`` on a ``datetime[ns]`` series now returns ``Timestamp`` instead
177177
of ``np.datetime64`` objects (:issue:`6810`)
178+
- change ``AssertionError`` to ``TypeError`` for invalid types passed to ``concat`` (:issue:`6583`)
178179

179180
Deprecations
180181
~~~~~~~~~~~~
@@ -400,6 +401,7 @@ Bug Fixes
400401
`header` kwarg (:issue:`6186`)
401402
- Bug in `DataFrame.plot` and `Series.plot` legend behave inconsistently when plotting to the same axes repeatedly (:issue:`6678`)
402403
- Internal tests for patching ``__finalize__`` / bug in merge not finalizing (:issue:`6923`, :issue:`6927`)
404+
- accept ``TextFileReader`` in ``concat``, which was affecting a common user idiom (:issue:`6583`)
403405

404406
pandas 0.13.1
405407
-------------

doc/source/v0.14.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ API changes
209209
- default sorting algorithm for ``Series.order`` is not ``quicksort``, to conform with ``Series.sort``
210210
(and numpy defaults)
211211
- add ``inplace`` keyword to ``Series.order/sort`` to make them inverses (:issue:`6859`)
212+
- accept ``TextFileReader`` in ``concat``, which was affecting a common user idiom (:issue:`6583`), this was a regression
213+
from 0.13.1
212214

213215
.. _whatsnew_0140.sql:
214216

pandas/tools/merge.py

+5-4
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

+18-2
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)