BUG: regression in DataFrame.combine_first with integer columns (GH14687) (#14886)

This commit is contained in:
Joris Van den Bossche 2016-12-16 10:43:42 +01:00 committed by GitHub
parent 5f777f40a8
commit 992dfbc6f5
3 changed files with 13 additions and 5 deletions

View File

@ -78,7 +78,7 @@ Bug Fixes
- Bug in clipboard functions on linux with python2 with unicode and separators (:issue:`13747`)
- Bug in clipboard functions on Windows 10 and python 3 (:issue:`14362`, :issue:`12807`)
- Bug in ``.to_clipboard()`` and Excel compat (:issue:`12529`)
- Bug in ``DataFrame.combine_first()`` for integer columns (:issue:`14687`).
- Bug in ``pd.read_csv()`` in which the ``dtype`` parameter was not being respected for empty data (:issue:`14712`)
- Bug in ``pd.read_csv()`` in which the ``nrows`` parameter was not being respected for large input when using the C engine for parsing (:issue:`7626`)

View File

@ -3665,10 +3665,8 @@ class DataFrame(NDFrame):
otherSeries[other_mask] = fill_value
# if we have different dtypes, possibily promote
if notnull(series).all():
new_dtype = this_dtype
otherSeries = otherSeries.astype(new_dtype)
else:
new_dtype = this_dtype
if not is_dtype_equal(this_dtype, other_dtype):
new_dtype = _find_common_type([this_dtype, other_dtype])
if not is_dtype_equal(this_dtype, new_dtype):
series = series.astype(new_dtype)

View File

@ -725,3 +725,13 @@ class TestDataFrameCombineFirst(tm.TestCase, TestData):
exp = pd.DataFrame({'P': exp_dts}, index=[1, 2, 3, 4, 5, 7])
tm.assert_frame_equal(res, exp)
self.assertEqual(res['P'].dtype, 'object')
def test_combine_first_int(self):
# GH14687 - integer series that do no align exactly
df1 = pd.DataFrame({'a': [0, 1, 3, 5]}, dtype='int64')
df2 = pd.DataFrame({'a': [1, 4]}, dtype='int64')
res = df1.combine_first(df2)
tm.assert_frame_equal(res, df1)
self.assertEqual(res['a'].dtype, 'int64')