Skip to content

Commit

Permalink
Add test for reverse operator at Series (#694)
Browse files Browse the repository at this point in the history
Added missing parts for the reverse operator at Series.
such as radd, rsub, and rdiv and so on.

And to make the result different from the reverse operator,
I made some changes to the data in the existing example.
  • Loading branch information
itholic authored and HyukjinKwon committed Aug 27, 2019
1 parent 4404178 commit 01f01a6
Showing 1 changed file with 70 additions and 21 deletions.
91 changes: 70 additions & 21 deletions databricks/koalas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,41 +73,55 @@
_add_example_SERIES = """
Examples
--------
>>> df = ks.DataFrame({'a': [1, 1, 1, np.nan],
... 'b': [1, np.nan, 1, np.nan]},
>>> df = ks.DataFrame({'a': [2, 2, 4, np.nan],
... 'b': [2, np.nan, 2, np.nan]},
... index=['a', 'b', 'c', 'd'], columns=['a', 'b'])
>>> df
a b
a 1.0 1.0
b 1.0 NaN
c 1.0 1.0
a 2.0 2.0
b 2.0 NaN
c 4.0 2.0
d NaN NaN
>>> df.a.add(df.b)
a 2.0
a 4.0
b NaN
c 2.0
c 6.0
d NaN
Name: a, dtype: float64
>>> df.a.radd(df.b)
a 4.0
b NaN
c 6.0
d NaN
Name: a, dtype: float64
"""

_sub_example_SERIES = """
Examples
--------
>>> df = ks.DataFrame({'a': [1, 1, 1, np.nan],
... 'b': [1, np.nan, 1, np.nan]},
>>> df = ks.DataFrame({'a': [2, 2, 4, np.nan],
... 'b': [2, np.nan, 2, np.nan]},
... index=['a', 'b', 'c', 'd'], columns=['a', 'b'])
>>> df
a b
a 1.0 1.0
b 1.0 NaN
c 1.0 1.0
a 2.0 2.0
b 2.0 NaN
c 4.0 2.0
d NaN NaN
>>> df.a.subtract(df.b)
a 0.0
b NaN
c 0.0
c 2.0
d NaN
Name: a, dtype: float64
>>> df.a.rsub(df.b)
a 0.0
b NaN
c -2.0
d NaN
Name: a, dtype: float64
"""
Expand All @@ -131,6 +145,13 @@
c 8.0
d NaN
Name: a, dtype: float64
>>> df.a.rmul(df.b)
a 4.0
b NaN
c 8.0
d NaN
Name: a, dtype: float64
"""

_div_example_SERIES = """
Expand All @@ -152,6 +173,13 @@
c 2.0
d NaN
Name: a, dtype: float64
>>> df.a.rdiv(df.b)
a 1.0
b NaN
c 0.5
d NaN
Name: a, dtype: float64
"""

_pow_example_SERIES = """
Expand All @@ -173,6 +201,13 @@
c 16.0
d NaN
Name: a, dtype: float64
>>> df.a.rpow(df.b)
a 0.0
b NaN
c -2.0
d NaN
Name: a, dtype: float64
"""

_mod_example_SERIES = """
Expand All @@ -194,6 +229,13 @@
c 0.0
d NaN
Name: a, dtype: float64
>>> df.a.rmod(df.b)
a 0.0
b NaN
c 2.0
d NaN
Name: a, dtype: float64
"""

_floordiv_example_SERIES = """
Expand All @@ -215,6 +257,13 @@
c 2.0
d NaN
Name: a, dtype: float64
>>> df.a.rfloordiv(df.b)
a 0.0
b NaN
c -2.0
d NaN
Name: a, dtype: float64
"""

T = TypeVar("T")
Expand Down Expand Up @@ -320,7 +369,7 @@ def radd(self, other):
return (other + self).rename(self.name)

radd.__doc__ = _flex_doc_SERIES.format(
desc='Addition',
desc='Reverse Addition',
op_name="+",
equiv="other + series",
reverse='add',
Expand All @@ -342,7 +391,7 @@ def rdiv(self, other):
return (other / self).rename(self.name)

rdiv.__doc__ = _flex_doc_SERIES.format(
desc='Floating division',
desc='Reverse Floating division',
op_name="/",
equiv="other / series",
reverse='div',
Expand All @@ -362,7 +411,7 @@ def rtruediv(self, other):
return (other / self).rename(self.name)

rtruediv.__doc__ = _flex_doc_SERIES.format(
desc='Floating division',
desc='Reverse Floating division',
op_name="/",
equiv="other / series",
reverse='truediv',
Expand All @@ -384,7 +433,7 @@ def rmul(self, other):
return (other * self).rename(self.name)

rmul.__doc__ = _flex_doc_SERIES.format(
desc='Multiplication',
desc='Reverse Multiplication',
op_name="*",
equiv="other * series",
reverse='mul',
Expand All @@ -406,7 +455,7 @@ def rsub(self, other):
return (other - self).rename(self.name)

rsub.__doc__ = _flex_doc_SERIES.format(
desc='Subtraction',
desc='Reverse Subtraction',
op_name="-",
equiv="other - series",
reverse='sub',
Expand All @@ -426,7 +475,7 @@ def rmod(self, other):
return (other % self).rename(self.name)

rmod.__doc__ = _flex_doc_SERIES.format(
desc='Modulo',
desc='Reverse Modulo',
op_name='%',
equiv='other % series',
reverse='mod',
Expand All @@ -446,7 +495,7 @@ def rpow(self, other):
return (other - self).rename(self.name)

rpow.__doc__ = _flex_doc_SERIES.format(
desc='Exponential power',
desc='Reverse Exponential power',
op_name='**',
equiv='other ** series',
reverse='pow',
Expand All @@ -466,7 +515,7 @@ def rfloordiv(self, other):
return (other - self).rename(self.name)

rfloordiv.__doc__ = _flex_doc_SERIES.format(
desc='Integer division',
desc='Reverse Integer division',
op_name='//',
equiv='other // series',
reverse='floordiv',
Expand Down

0 comments on commit 01f01a6

Please sign in to comment.