Skip to content

Commit ce1ffca

Browse files
committed
Fix all/any.
1 parent 795b4ed commit ce1ffca

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

databricks/koalas/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from databricks import koalas as ks # For running doctests and reference resolution in PyCharm.
3333
from databricks.koalas.internal import _InternalFrame
3434
from databricks.koalas.typedef import pandas_wraps
35-
from databricks.koalas.utils import align_diff_series
35+
from databricks.koalas.utils import align_diff_series, scol_for
3636

3737

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

584584
sdf = self._kdf._sdf.select(self._scol)
585-
col = self._scol
585+
col = scol_for(sdf, sdf.columns[0])
586586

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

647647
sdf = self._kdf._sdf.select(self._scol)
648-
col = self._scol
648+
col = scol_for(sdf, sdf.columns[0])
649649

650650
# Note that we're ignoring `None`s here for now.
651651
# any and every was added as of Spark 3.0

databricks/koalas/tests/test_series.py

+34
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,40 @@ def test_isnull(self):
254254
self.assert_eq(ks.notnull(), ps.notnull())
255255
self.assert_eq(ks.isnull(), ps.isnull())
256256

257+
def test_all(self):
258+
for ps in [pd.Series([True, True], name='x'),
259+
pd.Series([True, False], name='x'),
260+
pd.Series([0, 1], name='x'),
261+
pd.Series([1, 2, 3], name='x'),
262+
pd.Series([True, True, None], name='x'),
263+
pd.Series([True, False, None], name='x'),
264+
pd.Series([], name='x'),
265+
pd.Series([np.nan], name='x')]:
266+
ks = koalas.from_pandas(ps)
267+
self.assert_eq(ks.all(), ps.all())
268+
269+
ps = pd.Series([1, 2, 3, 4], name='x')
270+
ks = koalas.from_pandas(ps)
271+
272+
self.assert_eq((ks % 2 == 0).all(), (ps % 2 == 0).all())
273+
274+
def test_any(self):
275+
for ps in [pd.Series([False, False], name='x'),
276+
pd.Series([True, False], name='x'),
277+
pd.Series([0, 1], name='x'),
278+
pd.Series([1, 2, 3], name='x'),
279+
pd.Series([True, True, None], name='x'),
280+
pd.Series([True, False, None], name='x'),
281+
pd.Series([], name='x'),
282+
pd.Series([np.nan], name='x')]:
283+
ks = koalas.from_pandas(ps)
284+
self.assert_eq(ks.any(), ps.any())
285+
286+
ps = pd.Series([1, 2, 3, 4], name='x')
287+
ks = koalas.from_pandas(ps)
288+
289+
self.assert_eq((ks % 2 == 0).any(), (ps % 2 == 0).any())
290+
257291
def test_sort_values(self):
258292
ps = pd.Series([1, 2, 3, 4, 5, None, 7], name='0')
259293
ks = koalas.from_pandas(ps)

0 commit comments

Comments
 (0)