|
13 | 13 | from pandas.core.reshape.merge import merge, MergeError
|
14 | 14 | from pandas.util.testing import assert_frame_equal, assert_series_equal
|
15 | 15 | from pandas.core.dtypes.dtypes import CategoricalDtype
|
16 |
| -from pandas.core.dtypes.common import is_categorical_dtype, is_object_dtype |
| 16 | +from pandas.core.dtypes.common import ( |
| 17 | + is_categorical_dtype, |
| 18 | + is_object_dtype, |
| 19 | + is_float_dtype, |
| 20 | +) |
17 | 21 | from pandas import DataFrame, Index, MultiIndex, Series, Categorical
|
18 | 22 | import pandas.util.testing as tm
|
19 | 23 | from pandas.api.types import CategoricalDtype as CDT
|
@@ -1408,6 +1412,25 @@ def test_join_multi_dtypes(self, d1, d2):
|
1408 | 1412 | expected.sort_values(['k1', 'k2'], kind='mergesort', inplace=True)
|
1409 | 1413 | tm.assert_frame_equal(result, expected)
|
1410 | 1414 |
|
| 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]), |
| 1420 | + ]) |
| 1421 | + def test_merge_on_ints_floats(self, int_vals, float_vals): |
| 1422 | + # GH 16572 |
| 1423 | + # Check that float column is not cast to object if |
| 1424 | + # merging on float and int |
| 1425 | + A = DataFrame({'X': int_vals}) |
| 1426 | + B = DataFrame({'Y': float_vals}) |
| 1427 | + |
| 1428 | + res = A.merge(B, left_on='X', right_on='Y') |
| 1429 | + assert is_float_dtype(res['Y'].dtype) |
| 1430 | + |
| 1431 | + res = B.merge(A, left_on='Y', right_on='X') |
| 1432 | + assert is_float_dtype(res['Y'].dtype) |
| 1433 | + |
1411 | 1434 |
|
1412 | 1435 | @pytest.fixture
|
1413 | 1436 | def left():
|
|
0 commit comments