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

Fix column name as a tuple in multi column index #1191

Merged
merged 1 commit into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions databricks/koalas/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,9 +742,10 @@ def from_pandas(pdf: pd.DataFrame) -> '_InternalFrame':
index_map = [(SPARK_INDEX_NAME_FORMAT(i), None)
for i in range(len(index.levels))]
else:
index_map = [(SPARK_INDEX_NAME_FORMAT(i) if name is None else name,
name if name is None or isinstance(name, tuple) else (name,))
for i, name in enumerate(index.names)]
index_map = [
(SPARK_INDEX_NAME_FORMAT(i) if name is None else name_like_string(name),
name if name is None or isinstance(name, tuple) else (name,))
for i, name in enumerate(index.names)]
else:
name = index.name
index_map = [(name_like_string(name)
Expand Down
7 changes: 7 additions & 0 deletions databricks/koalas/tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,13 @@ def test_multiindex_from_product(self):

self.assert_eq(pidx, kidx)

def test_multiindex_tuple_column_name(self):
column_index = pd.MultiIndex.from_tuples([('a', 'x'), ('a', 'y'), ('b', 'z')])
pdf = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]], columns=column_index)
pdf.set_index(('a', 'x'), append=True, inplace=True)
kdf = ks.from_pandas(pdf)
self.assert_eq(pdf, kdf)

def test_len(self):
pidx = pd.Index(range(10000))
kidx = ks.Index(range(10000))
Expand Down