koalas icon indicating copy to clipboard operation
koalas copied to clipboard

Series.__getitem__ doesn't work when Series is given

Open harupy opened this issue 7 years ago • 2 comments

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.

harupy avatar Nov 25 '19 13:11 harupy

I found one comment about the concern of implementing __iter__ https://github.com/databricks/koalas/issues/1003#issuecomment-556908359

But personally it is not ideal way to raise this kind of exception. 🤔

guyao avatar Nov 25 '19 18:11 guyao

@guyao the issue is Series.getitem is not expected to take Series. I created a PR to address this.

harupy avatar Nov 26 '19 01:11 harupy