Skip to content

Commit

Permalink
Don't raise warning on merging int and float with nan (pandas-dev#21011)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche authored and tp committed May 13, 2018
1 parent a33994e commit 75e19cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,14 +955,14 @@ def _maybe_coerce_merge_keys(self):

# check whether ints and floats
elif is_integer_dtype(rk) and is_float_dtype(lk):
if not (lk == lk.astype(rk.dtype)).all():
if not (lk == lk.astype(rk.dtype))[~np.isnan(lk)].all():
warnings.warn('You are merging on int and float '
'columns where the float values '
'are not equal to their int '
'representation', UserWarning)

elif is_float_dtype(rk) and is_integer_dtype(lk):
if not (rk == rk.astype(lk.dtype)).all():
if not (rk == rk.astype(lk.dtype))[~np.isnan(rk)].all():
warnings.warn('You are merging on int and float '
'columns where the float values '
'are not equal to their int '
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/reshape/merge/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,13 @@ def test_merge_on_ints_floats_warning(self):
result = B.merge(A, left_on='Y', right_on='X')
assert_frame_equal(result, expected[['Y', 'X']])

# test no warning if float has NaNs
B = DataFrame({'Y': [np.nan, np.nan, 3.0]})

with tm.assert_produces_warning(None):
result = B.merge(A, left_on='Y', right_on='X')
assert_frame_equal(result, expected[['Y', 'X']])

@pytest.mark.parametrize('df1_vals, df2_vals', [
([0, 1, 2], ["0", "1", "2"]),
([0.0, 1.0, 2.0], ["0", "1", "2"]),
Expand Down

0 comments on commit 75e19cc

Please sign in to comment.