Skip to content

Commit fe735be

Browse files
committed
Merge pull request #10092 from mortada/fillna_bug
BUG: Series.fillna() raises if given a numerically convertible string
2 parents 3009585 + 8ccc9b3 commit fe735be

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

doc/source/whatsnew/v0.16.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,4 @@ Bug Fixes
420420
- Updated BigQuery connector to no longer use deprecated ``oauth2client.tools.run()`` (:issue:`8327`)
421421
- Bug in subclassed ``DataFrame``. It may not return the correct class, when slicing or subsetting it. (:issue:`9632`)
422422
- Bug in ``.median()`` where non-float null values are not handled correctly (:issue:`10040`)
423+
- Bug in Series.fillna() where it raises if a numerically convertible string is given (:issue:`10092`)

pandas/core/internals.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4017,7 +4017,8 @@ def _putmask_smart(v, m, n):
40174017
try:
40184018
nn = n[m]
40194019
nn_at = nn.astype(v.dtype)
4020-
if (nn == nn_at).all():
4020+
comp = (nn == nn_at)
4021+
if is_list_like(comp) and comp.all():
40214022
nv = v.copy()
40224023
nv[m] = nn_at
40234024
return nv

pandas/tests/test_series.py

+10
Original file line numberDiff line numberDiff line change
@@ -3654,6 +3654,16 @@ def test_fillna(self):
36543654
expected = Series([999,999,np.nan],index=[0,1,2])
36553655
assert_series_equal(result,expected)
36563656

3657+
# GH 9043
3658+
# make sure a string representation of int/float values can be filled
3659+
# correctly without raising errors or being converted
3660+
vals = ['0', '1.5', '-0.3']
3661+
for val in vals:
3662+
s = Series([0, 1, np.nan, np.nan, 4], dtype='float64')
3663+
result = s.fillna(val)
3664+
expected = Series([0, 1, val, val, 4], dtype='object')
3665+
assert_series_equal(result, expected)
3666+
36573667
def test_fillna_bug(self):
36583668
x = Series([nan, 1., nan, 3., nan], ['z', 'a', 'b', 'c', 'd'])
36593669
filled = x.fillna(method='ffill')

0 commit comments

Comments
 (0)