Skip to content

Commit 8aaf687

Browse files
committed
check if float values equal to int representation and add warning
1 parent 28c4358 commit 8aaf687

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

pandas/core/reshape/merge.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -914,16 +914,29 @@ def _maybe_coerce_merge_keys(self):
914914
continue
915915

916916
# check whether ints and floats
917-
if is_integer_dtype(rk) and is_float_dtype(lk):
917+
elif is_integer_dtype(rk) and is_float_dtype(lk):
918+
if not (lk == lk.astype(rk.dtype)).all():
919+
warnings.warn('You are merging on int and float '
920+
'columns where the float values '
921+
'are not equal to their int '
922+
'representation', UserWarning)
918923
continue
919924

920-
if is_float_dtype(rk) and is_integer_dtype(lk):
925+
elif is_float_dtype(rk) and is_integer_dtype(lk):
926+
if not (rk == rk.astype(lk.dtype)).all():
927+
warnings.warn('You are merging on int and float '
928+
'columns where the float values '
929+
'are not equal to their int '
930+
'representation', UserWarning)
921931
continue
922932

923933
# let's infer and see if we are ok
924-
if lib.infer_dtype(lk) == lib.infer_dtype(rk):
934+
elif lib.infer_dtype(lk) == lib.infer_dtype(rk):
925935
continue
926936

937+
else:
938+
pass
939+
927940
# Houston, we have a problem!
928941
# let's coerce to object if the dtypes aren't
929942
# categorical, otherwise coerce to the category

0 commit comments

Comments
 (0)