Skip to content

Commit e18b7c9

Browse files
committed
Add some checks for assuring that the left_index and right_index parameters have correct types. Tests added.
1 parent 7cad3f1 commit e18b7c9

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

doc/source/whatsnew/v0.19.1.txt

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ Performance Improvements
2525

2626

2727

28+
.. _whatsnew_0191.new_features:
29+
30+
New features
31+
~~~~~~~~~~~~
32+
- Add checks to assure that left_index and right_index are of type bool
33+
34+
2835

2936
.. _whatsnew_0191.bug_fixes:
3037

pandas/tools/merge.py

+9
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,15 @@ def __init__(self, left, right, how='inner', on=None,
472472
'can not merge DataFrame with instance of '
473473
'type {0}'.format(type(right)))
474474

475+
if not is_bool(left_index):
476+
raise ValueError(
477+
'left_index parameter must be of type bool, not '
478+
'{0}'.format(type(left_index)))
479+
if not is_bool(right_index):
480+
raise ValueError(
481+
'right_index parameter must be of type bool, not '
482+
'{0}'.format(type(right_index)))
483+
475484
# warn user when merging between different levels
476485
if left.columns.nlevels != right.columns.nlevels:
477486
msg = ('merging between different levels can give an unintended '

pandas/tools/tests/test_merge.py

+9
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ def test_merge_misspecified(self):
109109
self.assertRaises(ValueError, merge, self.df, self.df2,
110110
left_on=['key1'], right_on=['key1', 'key2'])
111111

112+
def test_index_and_on_parameters_confusion(self):
113+
self.assertRaises(ValueError, merge, self.df, self.df2, how='left',
114+
left_index=False, right_index=['key1', 'key2'])
115+
self.assertRaises(ValueError, merge, self.df, self.df2, how='left',
116+
left_index=['key1', 'key2'], right_index=False)
117+
self.assertRaises(ValueError, merge, self.df, self.df2, how='left',
118+
left_index=['key1', 'key2'],
119+
right_index=['key1', 'key2'])
120+
112121
def test_merge_overlap(self):
113122
merged = merge(self.left, self.left, on='key')
114123
exp_len = (self.left['key'].value_counts() ** 2).sum()

0 commit comments

Comments
 (0)