Skip to content

Commit b0e4589

Browse files
ivallespjorisvandenbossche
authored andcommitted
[Backport pandas-dev#14434] ERR: Checks for left_index and right_index merge parameters
Author: Iván Vallés Pérez <[email protected]> Closes pandas-dev#14434 from ivallesp/add-check-for-merge-indices and squashes the following commits: e18b7c9 [Iván Vallés Pérez] Add some checks for assuring that the left_index and right_index parameters have correct types. Tests added. (cherry picked from commit 2d3a739)
1 parent 9857248 commit b0e4589

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

doc/source/whatsnew/v0.19.1.txt

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Performance Improvements
2626

2727

2828

29+
2930
.. _whatsnew_0191.bug_fixes:
3031

3132
Bug Fixes
@@ -42,6 +43,9 @@ Bug Fixes
4243

4344

4445

46+
- ``pd.merge()`` will raise ``ValueError`` with non-boolean parameters in passed boolean type arguments (:issue:`14434`)
47+
48+
4549

4650
- Bug in ``pd.concat`` where names of the ``keys`` were not propagated to the resulting ``MultiIndex`` (:issue:`14252`)
4751
- Bug in ``pd.concat`` where ``axis`` cannot take string parameters ``'rows'`` or ``'columns'`` (:issue:`14369`)

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)