Skip to content

ENH: raise useful error message on invalid concat arguments #3559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
May 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pandas/tools/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,11 @@ 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, (tuple, list, dict)):
raise AssertionError('first argument must be a list of pandas '
'objects, you passed an object of type '
'"{0}"'.format(type(objs).__name__))

if join == 'outer':
self.intersect = False
elif join == 'inner':
Expand Down
8 changes: 7 additions & 1 deletion pandas/tools/tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from pandas.tseries.index import DatetimeIndex
from pandas.tools.merge import merge, concat, ordered_merge, MergeError
from pandas.util.testing import (assert_frame_equal, assert_series_equal,
assert_almost_equal, rands)
assert_almost_equal, rands,
makeCustomDataframe as mkdf)
import pandas.algos as algos
import pandas.util.testing as tm

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

def test_concat_invalid_first_argument(self):
df1 = mkdf(10, 2)
df2 = mkdf(10, 2)
self.assertRaises(AssertionError, concat, df1, df2)

class TestOrderedMerge(unittest.TestCase):

def setUp(self):
Expand Down