From 7e1f82aed260ca06911c440b5019292f9918ebcb Mon Sep 17 00:00:00 2001 From: Paul Reidy Date: Mon, 20 Nov 2017 22:42:22 +0000 Subject: [PATCH] check if float values equal to int representation and add warning --- pandas/core/reshape/merge.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 0062427e1f77d5..3eeeceaeb76ea0 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -914,16 +914,29 @@ def _maybe_coerce_merge_keys(self): continue # check whether ints and floats - if is_integer_dtype(rk) and is_float_dtype(lk): + elif is_integer_dtype(rk) and is_float_dtype(lk): + if not (lk == lk.astype(rk.dtype)).all(): + warnings.warn('You are merging on int and float ' + 'columns where the float values ' + 'are not equal to their int ' + 'representation', UserWarning) continue - if is_float_dtype(rk) and is_integer_dtype(lk): + elif is_float_dtype(rk) and is_integer_dtype(lk): + if not (rk == rk.astype(lk.dtype)).all(): + warnings.warn('You are merging on int and float ' + 'columns where the float values ' + 'are not equal to their int ' + 'representation', UserWarning) continue # let's infer and see if we are ok - if lib.infer_dtype(lk) == lib.infer_dtype(rk): + elif lib.infer_dtype(lk) == lib.infer_dtype(rk): continue + else: + pass + # Houston, we have a problem! # let's coerce to object if the dtypes aren't # categorical, otherwise coerce to the category