Skip to content

Commit

Permalink
BUG: Use context manager; add test from pandas-dev#17776
Browse files Browse the repository at this point in the history
  • Loading branch information
yeemey committed Oct 13, 2017
1 parent 5c5acd1 commit 039315a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 2 additions & 3 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,6 @@ 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 @@ -1526,10 +1525,10 @@ 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
9 changes: 8 additions & 1 deletion pandas/tests/reshape/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,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 039315a

Please sign in to comment.