Skip to content

Commit

Permalink
[Backport pandas-dev#14886] BUG: regression in DataFrame.combine_firs…
Browse files Browse the repository at this point in the history
…t with integer columns (GH14687) (pandas-dev#14886)

(cherry picked from commit 992dfbc)
  • Loading branch information
jorisvandenbossche committed Dec 24, 2016
1 parent 4359471 commit a509172
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.19.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
6 changes: 2 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3718,10 +3718,8 @@ def combine(self, other, func, fill_value=None, overwrite=True):
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)
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/frame/test_combine_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,3 +725,13 @@ def test_combine_first_period(self):
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')

0 comments on commit a509172

Please sign in to comment.