koalas icon indicating copy to clipboard operation
koalas copied to clipboard

DataFrame.reindex with a koalas Index parameter is not implemented

Open LucasG0 opened this issue 6 years ago • 0 comments

In pandas, we have :

>>> df = pd.DataFrame({"a": [1, 2, 3]}, index=["A", "B", "C"])
>>> df2 = pd.DataFrame({"a": [4, 5, 6]}, index=["A", "D", "B"])
>>> df.reindex(index=df2.index)
     a
A  1.0
D  NaN
B  2.0

But it is not implemented in koalas :

>>> df = ks.from_pandas(df)
>>> df2 = ks.from_pandas(df2)
>>> df = df.reindex(df2.index)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Dev\koalas\databricks\koalas\frame.py", line 7805, in reindex
    df = df._reindex_index(index, fill_value)
  File "D:\Dev\koalas\databricks\koalas\frame.py", line 7824, in _reindex_index
    kser = ks.Series(list(index))
  File "D:\Dev\koalas\databricks\koalas\indexes.py", line 1989, in __iter__
    return MissingPandasLikeIndex.__iter__(self)
  File "D:\Dev\koalas\databricks\koalas\missing\__init__.py", line 23, in unsupported_function
    class_name=class_name, method_name=method_name, 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.

It could be interesting to have this feature, I will submit a PR for this.

LucasG0 avatar Sep 01 '20 21:09 LucasG0