Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions databricks/koalas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1607,20 +1607,24 @@ def _fillna(self, value=None, method=None, axis=None, inplace=False, limit=None,
if (method is not None) and (method not in ["ffill", "pad", "backfill", "bfill"]):
raise ValueError("Expecting 'pad', 'ffill', 'backfill' or 'bfill'.")

if not self.spark.nullable:
if inplace:
return
else:
return self

scol = self.spark.column

if isinstance(self.spark.data_type, (FloatType, DoubleType)):
cond = scol.isNull() | F.isnan(scol)
else:
if not self.spark.nullable:
if inplace:
return
else:
return self
cond = scol.isNull()

if value is not None:
if not isinstance(value, (float, int, str, bool)):
raise TypeError("Unsupported type %s" % type(value))
if limit is not None:
raise ValueError("limit parameter for value is not support now")
scol = F.when(scol.isNull(), value).otherwise(scol)
scol = F.when(cond, value).otherwise(scol)
else:
if method in ["ffill", "pad"]:
func = F.last
Expand All @@ -1642,7 +1646,7 @@ def _fillna(self, value=None, method=None, axis=None, inplace=False, limit=None,
.orderBy(NATURAL_ORDER_COLUMN_NAME)
.rowsBetween(begin, end)
)
scol = F.when(scol.isNull(), func(scol, True).over(window)).otherwise(scol)
scol = F.when(cond, func(scol, True).over(window)).otherwise(scol)
kseries = self._with_new_scol(scol).rename(self.name)
if inplace:
self._internal = kseries._internal
Expand Down
11 changes: 11 additions & 0 deletions databricks/koalas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def test_fillna(self):
kser = ks.from_pandas(pser)

self.assert_eq(kser.fillna(0), pser.fillna(0))
self.assert_eq(kser.fillna(np.nan).fillna(0), pser.fillna(np.nan).fillna(0))

kser.fillna(0, inplace=True)
pser.fillna(0, inplace=True)
Expand All @@ -220,6 +221,16 @@ def test_fillna(self):
pser.fillna(0, inplace=True)
self.assert_eq(kser, pser)

pser = pd.Series([1, 2, 3, 4, 5, 6], name="x")
kser = ks.from_pandas(pser)

pser.loc[3] = np.nan
kser.loc[3] = np.nan

self.assert_eq(kser.fillna(0), pser.fillna(0))
self.assert_eq(kser.fillna(method="ffill"), pser.fillna(method="ffill"))
self.assert_eq(kser.fillna(method="bfill"), pser.fillna(method="bfill"))

def test_dropna(self):
pser = pd.Series([np.nan, 2, 3, 4, np.nan, 6], name="x")

Expand Down