Skip to content

Commit

Permalink
Rebase BUG: Ignore division by 0 when merging empty dataframes (panda…
Browse files Browse the repository at this point in the history
  • Loading branch information
yeemey committed Oct 14, 2017
1 parent 3c964a4 commit ccbf927
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,7 @@ def _sort_labels(uniques, left, right):


def _get_join_keys(llab, rlab, shape, sort):
np.seterr(divide='ignore')

# how many levels can be done without overflow
pred = lambda i: not is_int64_overflow_possible(shape[:i])
Expand All @@ -1525,9 +1526,11 @@ 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
np.seterr(divide='warn')

if nlev == len(shape): # all done!
return lkey, rkey
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/reshape/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,14 @@ 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
import warnings
a = pd.DataFrame({'a': [], 'b': [], 'c': []})
with warnings.catch_warnings(record=True) as record:
merge(a, a, on=('a', 'b'))
assert len(record) == 0


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

0 comments on commit ccbf927

Please sign in to comment.