Skip to content

Fix IndexOpsMixin.all/any. #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2019
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
6 changes: 3 additions & 3 deletions databricks/koalas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from databricks import koalas as ks # For running doctests and reference resolution in PyCharm.
from databricks.koalas.internal import _InternalFrame
from databricks.koalas.typedef import pandas_wraps
from databricks.koalas.utils import align_diff_series
from databricks.koalas.utils import align_diff_series, scol_for


def _column_op(f):
Expand Down Expand Up @@ -582,7 +582,7 @@ def all(self, axis: Union[int, str] = 0) -> bool:
raise ValueError('axis should be either 0 or "index" currently.')

sdf = self._kdf._sdf.select(self._scol)
col = self._scol
col = scol_for(sdf, sdf.columns[0])

# Note that we're ignoring `None`s here for now.
# any and every was added as of Spark 3.0
Expand Down Expand Up @@ -645,7 +645,7 @@ def any(self, axis: Union[int, str] = 0) -> bool:
raise ValueError('axis should be either 0 or "index" currently.')

sdf = self._kdf._sdf.select(self._scol)
col = self._scol
col = scol_for(sdf, sdf.columns[0])

# Note that we're ignoring `None`s here for now.
# any and every was added as of Spark 3.0
Expand Down
34 changes: 34 additions & 0 deletions databricks/koalas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,40 @@ def test_isnull(self):
self.assert_eq(ks.notnull(), ps.notnull())
self.assert_eq(ks.isnull(), ps.isnull())

def test_all(self):
for ps in [pd.Series([True, True], name='x'),
pd.Series([True, False], name='x'),
pd.Series([0, 1], name='x'),
pd.Series([1, 2, 3], name='x'),
pd.Series([True, True, None], name='x'),
pd.Series([True, False, None], name='x'),
pd.Series([], name='x'),
pd.Series([np.nan], name='x')]:
ks = koalas.from_pandas(ps)
self.assert_eq(ks.all(), ps.all())

ps = pd.Series([1, 2, 3, 4], name='x')
ks = koalas.from_pandas(ps)

self.assert_eq((ks % 2 == 0).all(), (ps % 2 == 0).all())

def test_any(self):
for ps in [pd.Series([False, False], name='x'),
pd.Series([True, False], name='x'),
pd.Series([0, 1], name='x'),
pd.Series([1, 2, 3], name='x'),
pd.Series([True, True, None], name='x'),
pd.Series([True, False, None], name='x'),
pd.Series([], name='x'),
pd.Series([np.nan], name='x')]:
ks = koalas.from_pandas(ps)
self.assert_eq(ks.any(), ps.any())

ps = pd.Series([1, 2, 3, 4], name='x')
ks = koalas.from_pandas(ps)

self.assert_eq((ks % 2 == 0).any(), (ps % 2 == 0).any())

def test_sort_values(self):
ps = pd.Series([1, 2, 3, 4, 5, None, 7], name='0')
ks = koalas.from_pandas(ps)
Expand Down