Skip to content

Commit ec907a4

Browse files
committed
test for merge results
1 parent e2f222c commit ec907a4

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

pandas/tests/reshape/test_merge.py

+26-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from pandas.core.dtypes.common import (
1717
is_categorical_dtype,
1818
is_object_dtype,
19-
is_float_dtype,
2019
)
2120
from pandas import DataFrame, Index, MultiIndex, Series, Categorical
2221
import pandas.util.testing as tm
@@ -1412,24 +1411,41 @@ def test_join_multi_dtypes(self, d1, d2):
14121411
expected.sort_values(['k1', 'k2'], kind='mergesort', inplace=True)
14131412
tm.assert_frame_equal(result, expected)
14141413

1415-
@pytest.mark.parametrize('int_vals, float_vals', [
1416-
([1, 2, 3], [1.0, 2.0, 3.0]),
1417-
([1, 2, 3], [1.0, 3.0]),
1418-
([1, 2], [1.0, 2.0, 3.0]),
1419-
([1, 2, 3], [1.1, 2.5, 3.0]),
1414+
@pytest.mark.parametrize('int_vals, float_vals, exp_vals', [
1415+
([1, 2, 3], [1.0, 2.0, 3.0], {'X': [1, 2, 3], 'Y': [1.0, 2.0, 3.0]}),
1416+
([1, 2, 3], [1.0, 3.0], {'X': [1, 3], 'Y': [1.0, 3.0]}),
1417+
([1, 2], [1.0, 2.0, 3.0], {'X': [1, 2], 'Y': [1.0, 2.0]}),
14201418
])
1421-
def test_merge_on_ints_floats(self, int_vals, float_vals):
1419+
def test_merge_on_ints_floats(self, int_vals, float_vals, exp_vals):
14221420
# GH 16572
14231421
# Check that float column is not cast to object if
1424-
# merging on float and int
1422+
# merging on float and int columns
14251423
A = DataFrame({'X': int_vals})
14261424
B = DataFrame({'Y': float_vals})
1425+
exp_res = DataFrame(exp_vals)
14271426

14281427
res = A.merge(B, left_on='X', right_on='Y')
1429-
assert is_float_dtype(res['Y'].dtype)
1428+
assert_frame_equal(res, exp_res)
14301429

14311430
res = B.merge(A, left_on='Y', right_on='X')
1432-
assert is_float_dtype(res['Y'].dtype)
1431+
assert_frame_equal(res, exp_res[['Y', 'X']])
1432+
1433+
def test_merge_on_ints_floats_warning(self):
1434+
# GH 16572
1435+
# merge will produce a warning when merging on int and
1436+
# float columns where the float values are not exactly
1437+
# equal to their int representation
1438+
A = DataFrame({'X': [1, 2, 3]})
1439+
B = DataFrame({'Y': [1.1, 2.5, 3.0]})
1440+
exp_res = DataFrame({'X': [3], 'Y': [3.0]})
1441+
1442+
with tm.assert_produces_warning(UserWarning):
1443+
res = A.merge(B, left_on='X', right_on='Y')
1444+
assert_frame_equal(res, exp_res)
1445+
1446+
with tm.assert_produces_warning(UserWarning):
1447+
res = B.merge(A, left_on='Y', right_on='X')
1448+
assert_frame_equal(res, exp_res[['Y', 'X']])
14331449

14341450

14351451
@pytest.fixture

0 commit comments

Comments
 (0)