Skip to content

Commit 3614233

Browse files
committed
ENH: raise useful error message on invalid concat arguments
1 parent 4670e9f commit 3614233

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pandas/tools/merge.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,11 @@ class _Concatenator(object):
888888
def __init__(self, objs, axis=0, join='outer', join_axes=None,
889889
keys=None, levels=None, names=None,
890890
ignore_index=False, verify_integrity=False):
891+
if not isinstance(objs, (tuple, list, dict)):
892+
raise AssertionError('first argument must be a list of pandas '
893+
'objects, you passed an object of type '
894+
'"{0}"'.format(type(objs).__name__))
895+
891896
if join == 'outer':
892897
self.intersect = False
893898
elif join == 'inner':

pandas/tools/tests/test_merge.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from pandas.tseries.index import DatetimeIndex
1414
from pandas.tools.merge import merge, concat, ordered_merge, MergeError
1515
from pandas.util.testing import (assert_frame_equal, assert_series_equal,
16-
assert_almost_equal, rands)
16+
assert_almost_equal, rands,
17+
makeCustomDataframe as mkdf)
1718
import pandas.algos as algos
1819
import pandas.util.testing as tm
1920

@@ -1689,6 +1690,11 @@ def test_concat_series_axis1_same_names_ignore_index(self):
16891690
result = concat([s1, s2], axis=1, ignore_index=True)
16901691
self.assertTrue(np.array_equal(result.columns, [0, 1]))
16911692

1693+
def test_concat_invalid_first_argument(self):
1694+
df1 = mkdf(10, 2)
1695+
df2 = mkdf(10, 2)
1696+
self.assertRaises(AssertionError, concat, df1, df2)
1697+
16921698
class TestOrderedMerge(unittest.TestCase):
16931699

16941700
def setUp(self):

0 commit comments

Comments
 (0)