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

Enable creating Index from list like 'Index([1, 2, 3])' #986

Merged
merged 4 commits into from
Nov 4, 2019
Merged
Changes from 2 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
10 changes: 9 additions & 1 deletion databricks/koalas/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,17 @@ class Index(IndexOpsMixin):

>>> ks.DataFrame({'a': [1, 2, 3]}, index=list('abc')).index
Index(['a', 'b', 'c'], dtype='object')

>>> Index([1, 2, 3])
Int64Index([1, 2, 3], dtype='int64')

>>> Index(list('abc'))
Index(['a', 'b', 'c'], dtype='object')
"""

def __init__(self, kdf: DataFrame, scol: Optional[spark.Column] = None) -> None:
def __init__(self, kdf_or_names: Union[DataFrame, list],
scol: Optional[spark.Column] = None) -> None:
kdf = DataFrame(index=kdf_or_names) if isinstance(kdf_or_names, list) else kdf_or_names
itholic marked this conversation as resolved.
Show resolved Hide resolved
if scol is None:
scol = kdf._internal.index_scols[0]
internal = kdf._internal.copy(scol=scol,
Expand Down