Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions databricks/koalas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ def wrapper(self, *args):
args = [arg._scol if isinstance(arg, IndexOpsMixin) else arg for arg in args]
scol = f(self._scol, *args)
scol = booleanize_null(self._scol, scol, f)
# PySpark and pandas have a different way to calculate modulo operation.
# Below lines are needed for closing the gap.
if f is spark.Column.__mod__:
scol = F.when((self._scol * args[0] < 0) & (scol != 0), scol + args[0]).otherwise(
scol
)
elif f is spark.Column.__rmod__:
scol = F.when(
(self._scol * args[0] < 0) & (scol != 0), scol + self._scol
).otherwise(scol)

return self._with_new_scol(scol)
else:
Expand Down
12 changes: 12 additions & 0 deletions databricks/koalas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,3 +1372,15 @@ def test_take(self):
self.assertRaises(ValueError, lambda: kser.take("1"))
self.assertRaises(ValueError, lambda: kser.take({1, 2}))
self.assertRaises(ValueError, lambda: kser.take({1: None, 2: None}))

def test_mod(self):
pser = pd.Series([100, None, -300, None, 500, -700], name="Koalas")
kser = ks.from_pandas(pser)

self.assert_eq(repr(kser.mod(-150)), repr(pser.mod(-150)))

def test_rmod(self):
pser = pd.Series([100, None, -300, None, 500, -700], name="Koalas")
kser = ks.from_pandas(pser)

self.assert_eq(repr(kser.rmod(-150)), repr(pser.rmod(-150)))