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

Impelment DataFrame.keys #937

Merged
merged 2 commits into from
Oct 19, 2019
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
25 changes: 25 additions & 0 deletions databricks/koalas/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7405,6 +7405,31 @@ def gen_new_column_index_entry(column_index_entry):
else:
return DataFrame(internal)

def keys(self):
"""
Return alias for columns.

Returns
-------
Index
Columns of the DataFrame.

Examples
--------
>>> df = ks.DataFrame([[1, 2], [4, 5], [7, 8]],
... index=['cobra', 'viper', 'sidewinder'],
... columns=['max_speed', 'shield'])
>>> df
max_speed shield
cobra 1 2
viper 4 5
sidewinder 7 8

>>> df.keys()
Index(['max_speed', 'shield'], dtype='object')
"""
itholic marked this conversation as resolved.
Show resolved Hide resolved
return self.columns

def _get_from_multiindex_column(self, key):
""" Select columns from multi-index columns.

Expand Down
1 change: 0 additions & 1 deletion databricks/koalas/missing/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class _MissingPandasLikeDataFrame(object):
interpolate = unsupported_function('interpolate')
iterrows = unsupported_function('iterrows')
itertuples = unsupported_function('itertuples')
keys = unsupported_function('keys')
last = unsupported_function('last')
last_valid_index = unsupported_function('last_valid_index')
lookup = unsupported_function('lookup')
Expand Down
8 changes: 8 additions & 0 deletions databricks/koalas/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2161,3 +2161,11 @@ def test_to_spark(self):

with self.assertRaisesRegex(ValueError, "length of index columns.*1.*3"):
kdf.to_spark(index_col=["x", "y", "z"])

def test_keys(self):
kdf = ks.DataFrame([[1, 2], [4, 5], [7, 8]],
index=['cobra', 'viper', 'sidewinder'],
columns=['max_speed', 'shield'])
pdf = kdf.to_pandas()

self.assert_eq(kdf.keys(), pdf.keys())
1 change: 1 addition & 0 deletions docs/source/reference/frame.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Indexing, iteration
DataFrame.iloc
DataFrame.items
DataFrame.iteritems
DataFrame.keys
DataFrame.xs
DataFrame.get

Expand Down