Repository: databricks/koalas

Issue:
Series.__getitem__ doesn't work when Series is given
```python
import pandas as pd
from databricks import koalas as ks

pser = pd.Series([1, 2, 3])

>>> pser[pser == 1]
0    1
dtype: int64

kser = ks.from_pandas(pser)

>>> kser[kser == 1]

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/harutaka/.pyenv/versions/anaconda3-5.3.1/envs/kp-dev-env/lib/python3.6/site-packages/databricks/koalas/series.py", line 4188, in __getitem__
    for level, index in enumerate(key)]
  File "/Users/harutaka/.pyenv/versions/anaconda3-5.3.1/envs/kp-dev-env/lib/python3.6/site-packages/databricks/koalas/series.py", line 4188, in <listcomp>
    for level, index in enumerate(key)]
  File "/Users/harutaka/.pyenv/versions/anaconda3-5.3.1/envs/kp-dev-env/lib/python3.6/site-packages/pyspark/sql/column.py", line 115, in _
    njc = getattr(self._jc, name)(jc)
  File "/Users/harutaka/.pyenv/versions/anaconda3-5.3.1/envs/kp-dev-env/lib/python3.6/site-packages/py4j/java_gateway.py", line 1248, in __call__
    args_command, temp_args = self._build_args(*args)
  File "/Users/harutaka/.pyenv/versions/anaconda3-5.3.1/envs/kp-dev-env/lib/python3.6/site-packages/py4j/java_gateway.py", line 1212, in _build_args
    (new_args, temp_args) = self._get_args(args)
  File "/Users/harutaka/.pyenv/versions/anaconda3-5.3.1/envs/kp-dev-env/lib/python3.6/site-packages/py4j/java_gateway.py", line 1199, in _get_args
    temp_arg = converter.convert(arg, self.gateway_client)
  File "/Users/harutaka/.pyenv/versions/anaconda3-5.3.1/envs/kp-dev-env/lib/python3.6/site-packages/py4j/java_collections.py", line 512, in convert
    for key in object.keys():
  File "/Users/harutaka/.pyenv/versions/anaconda3-5.3.1/envs/kp-dev-env/lib/python3.6/site-packages/databricks/koalas/indexes.py", line 492, in __iter__
    return _MissingPandasLikeIndex.__iter__(self)
  File "/Users/harutaka/.pyenv/versions/anaconda3-5.3.1/envs/kp-dev-env/lib/python3.6/site-packages/databricks/koalas/missing/__init__.py", line 24, in unsupported_function
    reason=reason)
databricks.koalas.exceptions.PandasNotImplementedError: The method `pd.Index.__iter__()` is not implemented. If you want to collect your data as an NumPy array, use 'to_numpy()' instead.
```


Discussion:

Resolving patch:
diff --git a/databricks/koalas/series.py b/databricks/koalas/series.py
--- a/databricks/koalas/series.py
+++ b/databricks/koalas/series.py
@@ -4215,6 +4215,11 @@ def __len__(self):
         return len(self.to_dataframe())
 
     def __getitem__(self, key):
+        if isinstance(key, Series) and isinstance(key.spark_type, BooleanType):
+            self._kdf["__temp_col__"] = key
+            sdf = self._kdf._sdf.filter(F.col("__temp_col__")).drop("__temp_col__")
+            return _col(DataFrame(_InternalFrame(sdf=sdf, index_map=self._internal.index_map)))
+
         if not isinstance(key, tuple):
             key = (key,)
         if len(self._internal._index_map) < len(key):


Test patch:
diff --git a/databricks/koalas/tests/test_ops_on_diff_frames.py b/databricks/koalas/tests/test_ops_on_diff_frames.py
--- a/databricks/koalas/tests/test_ops_on_diff_frames.py
+++ b/databricks/koalas/tests/test_ops_on_diff_frames.py
@@ -217,6 +217,15 @@ def test_arithmetic_chain(self):
             (kdf1 + kdf2 - kdf3).sort_index(),
             (pdf1 + pdf2 - pdf3).sort_index(), almost=True)
 
+    def test_getitem_boolean_series(self):
+        pdf1 = pd.DataFrame({'A': [0, 1, 2, 3, 4], 'B': [100, 200, 300, 400, 500]})
+        pdf2 = pd.DataFrame({'A': [0, -1, -2, -3, -4], 'B': [-100, -200, -300, -400, -500]})
+        kdf1 = ks.from_pandas(pdf1)
+        kdf2 = ks.from_pandas(pdf2)
+
+        self.assert_eq(pdf1.A[pdf2.A > 100],
+                       kdf1.A[kdf2.A > 100].sort_index())
+
     def test_bitwise(self):
         pser1 = pd.Series([True, False, True, False, np.nan, np.nan, True, False, np.nan])
         pser2 = pd.Series([True, False, False, True, True, False, np.nan, np.nan, np.nan])
diff --git a/databricks/koalas/tests/test_series.py b/databricks/koalas/tests/test_series.py
--- a/databricks/koalas/tests/test_series.py
+++ b/databricks/koalas/tests/test_series.py
@@ -881,6 +881,7 @@ def test_getitem(self):
 
         self.assert_eq(kser['A'], pser['A'])
         self.assert_eq(kser['B'], pser['B'])
+        self.assert_eq(kser[kser > 15], pser[pser > 15])
 
         # for MultiIndex
         midx = pd.MultiIndex([['a', 'b', 'c'],
@@ -895,6 +896,7 @@ def test_getitem(self):
 
         self.assert_eq(kser['a'], pser['a'])
         self.assert_eq(kser['a', 'lama'], pser['a', 'lama'])
+        self.assert_eq(kser[kser > 1.5], pser[pser > 1.5])
 
         msg = r"'Key length \(4\) exceeds index depth \(3\)'"
         with self.assertRaisesRegex(KeyError, msg):