Skip to content

Commit

Permalink
BUG: Ignore division by 0 when merging empty dataframes (pandas-dev#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
yeemey committed Oct 16, 2017
1 parent 5c0b20a commit bbf1849
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,8 @@ def _get_join_keys(llab, rlab, shape, sort):
rkey = stride * rlab[0].astype('i8', subok=False, copy=False)

for i in range(1, nlev):
stride //= shape[i]
with np.errstate(divide='ignore'):
stride //= shape[i]
lkey += llab[i] * stride
rkey += rlab[i] * stride

Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/reshape/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,12 @@ def test_validation(self):
result = merge(left, right, on=['a', 'b'], validate='1:1')
assert_frame_equal(result, expected_multi)

def test_merge_two_empty_df_no_division_error(self):
# GH17776, PR #17846
a = pd.DataFrame({'a': [], 'b': [], 'c': []})
with np.errstate(divide='raise'):
merge(a, a, on=('a', 'b'))


def _check_merge(x, y):
for how in ['inner', 'left', 'outer']:
Expand Down

0 comments on commit bbf1849

Please sign in to comment.