Skip to content
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

sort_index is not working with MultiIndex #634

Closed
garawalid opened this issue Aug 10, 2019 · 4 comments · Fixed by #637
Closed

sort_index is not working with MultiIndex #634

garawalid opened this issue Aug 10, 2019 · 4 comments · Fixed by #637
Assignees
Labels
enhancement New feature or request

Comments

@garawalid
Copy link
Contributor

DataFrame.sort_index() is not working when the DataFrame uses MultiIndex.

Reproduce the error:

import pandas as pd
import databricks.koalas as ks

pdf = pd.DataFrame({
    ('x', 'a', '1'): [1, 2, 3],
    ('x', 'b', '2'): [4, 5, 6],
    ('y.z', 'c.d', '3'): [7, 8, 9],
    ('x', 'b', '4'): [10, 11, 12],
}, index=[0, 1, 3])

kdf = ks.from_pandas(pdf)

kdf.sort_index()
Traceback (most recent call last):
  File "/home/xxx/databricks/koalas/tests/bug.py", line 15, in <module>
    kdf.sort_index()
  File "/home/xxx/databricks/koalas/frame.py", line 4295, in sort_index
    inplace=inplace, na_position=na_position)
  File "/home/xxx/databricks/koalas/frame.py", line 4191, in sort_values
    for colname, asc in zip(by, ascending)]
  File "/home/xxx/databricks/koalas/frame.py", line 4191, in <listcomp>
    for colname, asc in zip(by, ascending)]
  File "/home/xxx/databricks/koalas/frame.py", line 6343, in __getitem__
    return self._pd_getitem(key)
  File "/home/xxx/databricks/koalas/frame.py", line 6280, in _pd_getitem
    return self._get_from_multiindex_column((key,))
  File "/home/xxx/databricks/koalas/frame.py", line 6235, in _get_from_multiindex_column
    raise KeyError(k)
KeyError: '__index_level_0__'
@garawalid
Copy link
Contributor Author

cc @ueshin

@HyukjinKwon HyukjinKwon added the enhancement New feature or request label Aug 12, 2019
@ueshin
Copy link
Collaborator

ueshin commented Aug 12, 2019

Thanks for the report. I'll work on this.

@ueshin ueshin self-assigned this Aug 12, 2019
ueshin added a commit that referenced this issue Aug 13, 2019
ueshin pushed a commit that referenced this issue Aug 26, 2019
Resolves #511, #636. 
In the test, the `kdf` is converted to Pandas DataFrame in order to use `sort_index()`. I'll update the test once #634 resolved.
@NA-Dev
Copy link

NA-Dev commented Aug 16, 2022

I am sorting a dataframe with multiIndex where one is a string, and one is a date. The sorting is not working properly, as I can see dates are still out of order. Python 3.9 Pandas 1.4.2

Screenshot 2022-08-16 124124

@itholic
Copy link
Contributor

itholic commented Aug 18, 2022

@NA-Dev Would you mind filing a ticket to Apache Spark JIRA ??

Koalas is ported into PySpark as pandas API on Spark.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants