Skip to content

Commit 965caf2

Browse files
author
Christopher C. Aycock
committed
Verify that 'by' parameters are the same length
1 parent 4a2cc09 commit 965caf2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pandas/tests/tools/test_merge_asof.py

+4
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ def test_multiby_indexed(self):
399399

400400
assert_frame_equal(expected, result)
401401

402+
with self.assertRaises(MergeError):
403+
pd.merge_asof(left, right, left_index=True, right_index=True,
404+
left_by=['k1', 'k2'], right_by=['k1'])
405+
402406
def test_basic2(self):
403407

404408
expected = self.read_data('asof2.csv')

pandas/tools/merge.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1165,14 +1165,17 @@ def _validate_specification(self):
11651165
if self.left_by is not None and self.right_by is None:
11661166
raise MergeError('missing right_by')
11671167

1168-
# add by to our key-list so we can have it in the
1168+
# add 'by' to our key-list so we can have it in the
11691169
# output as a key
11701170
if self.left_by is not None:
11711171
if not is_list_like(self.left_by):
11721172
self.left_by = [self.left_by]
11731173
if not is_list_like(self.right_by):
11741174
self.right_by = [self.right_by]
11751175

1176+
if len(self.left_by) != len(self.right_by):
1177+
raise MergeError('left_by and right_by must be same length')
1178+
11761179
self.left_on = self.left_by + list(self.left_on)
11771180
self.right_on = self.right_by + list(self.right_on)
11781181

0 commit comments

Comments
 (0)