Skip to content

Commit

Permalink
BUG: Series.fillna() raises if given a numerically convertible string
Browse files Browse the repository at this point in the history
  • Loading branch information
mortada committed May 9, 2015
1 parent 6c80f68 commit 8ccc9b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.16.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,4 @@ Bug Fixes
- Updated BigQuery connector to no longer use deprecated ``oauth2client.tools.run()`` (:issue:`8327`)
- Bug in subclassed ``DataFrame``. It may not return the correct class, when slicing or subsetting it. (:issue:`9632`)
- Bug in ``.median()`` where non-float null values are not handled correctly (:issue:`10040`)
- Bug in Series.fillna() where it raises if a numerically convertible string is given (:issue:`10092`)
3 changes: 2 additions & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4017,7 +4017,8 @@ def _putmask_smart(v, m, n):
try:
nn = n[m]
nn_at = nn.astype(v.dtype)
if (nn == nn_at).all():
comp = (nn == nn_at)
if is_list_like(comp) and comp.all():
nv = v.copy()
nv[m] = nn_at
return nv
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3654,6 +3654,16 @@ def test_fillna(self):
expected = Series([999,999,np.nan],index=[0,1,2])
assert_series_equal(result,expected)

# GH 9043
# make sure a string representation of int/float values can be filled
# correctly without raising errors or being converted
vals = ['0', '1.5', '-0.3']
for val in vals:
s = Series([0, 1, np.nan, np.nan, 4], dtype='float64')
result = s.fillna(val)
expected = Series([0, 1, val, val, 4], dtype='object')
assert_series_equal(result, expected)

def test_fillna_bug(self):
x = Series([nan, 1., nan, 3., nan], ['z', 'a', 'b', 'c', 'd'])
filled = x.fillna(method='ffill')
Expand Down

0 comments on commit 8ccc9b3

Please sign in to comment.