Skip to content

Commit 95f30ca

Browse files
committed
BUG: fix fillna on series with integers, close #1788
1 parent c99d9cd commit 95f30ca

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pandas/core/series.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from pandas.core.common import (isnull, notnull, _is_bool_indexer,
1818
_default_index, _maybe_upcast,
19-
_asarray_tuplesafe)
19+
_asarray_tuplesafe, is_integer_dtype)
2020
from pandas.core.index import (Index, MultiIndex, InvalidIndexError,
2121
_ensure_index, _handle_legacy_indexes)
2222
from pandas.core.indexing import _SeriesIndexer
@@ -386,6 +386,10 @@ def __init__(self, data=None, index=None, dtype=None, name=None,
386386
def _constructor(self):
387387
return Series
388388

389+
@property
390+
def _can_hold_na(self):
391+
return not is_integer_dtype(self.dtype)
392+
389393
def __hash__(self):
390394
raise TypeError('unhashable type')
391395

@@ -2157,6 +2161,9 @@ def fillna(self, value=None, method='pad', inplace=False,
21572161
-------
21582162
filled : Series
21592163
"""
2164+
if not self._can_hold_na:
2165+
return self.copy() if not inplace else self
2166+
21602167
if value is not None:
21612168
result = self.copy() if not inplace else self
21622169
mask = isnull(self.values)

pandas/tests/test_series.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,6 +2697,11 @@ def test_isin(self):
26972697
expected = Series([True, False, True, False, False, False, True, True])
26982698
assert_series_equal(result, expected)
26992699

2700+
def test_fillna_int(self):
2701+
s = Series(np.random.randint(-100, 100, 50))
2702+
self.assert_(s.fillna(inplace=True) is s)
2703+
assert_series_equal(s.fillna(inplace=False), s)
2704+
27002705
#-------------------------------------------------------------------------------
27012706
# TimeSeries-specific
27022707

0 commit comments

Comments
 (0)