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

Implement Series.keys #935

Merged
merged 3 commits into from
Oct 21, 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
1 change: 0 additions & 1 deletion databricks/koalas/missing/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class _MissingPandasLikeSeries(object):
interpolate = unsupported_function('interpolate')
items = unsupported_function('items')
iteritems = unsupported_function('iteritems')
keys = unsupported_function('keys')
last = unsupported_function('last')
last_valid_index = unsupported_function('last_valid_index')
mad = unsupported_function('mad')
Expand Down
31 changes: 31 additions & 0 deletions databricks/koalas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3223,6 +3223,37 @@ def copy(self) -> 'Series':
"""
return _col(DataFrame(self._internal.copy()))

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

Returns
-------
Index
Index of the Series.

Examples
--------
>>> midx = pd.MultiIndex([['lama', 'cow', 'falcon'],
... ['speed', 'weight', 'length']],
... [[0, 0, 0, 1, 1, 1, 2, 2, 2],
... [0, 1, 2, 0, 1, 2, 0, 1, 2]])
>>> kser = ks.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3], index=midx)

>>> kser.keys() # doctest: +SKIP
MultiIndex([( 'lama', 'speed'),
( 'lama', 'weight'),
( 'lama', 'length'),
( 'cow', 'speed'),
( 'cow', 'weight'),
( 'cow', 'length'),
('falcon', 'speed'),
('falcon', 'weight'),
('falcon', 'length')],
)
"""
itholic marked this conversation as resolved.
Show resolved Hide resolved
return self.index

# TODO: 'regex', 'method' parameter
def replace(self, to_replace=None, value=None, regex=False) -> 'Series':
"""
Expand Down
10 changes: 10 additions & 0 deletions databricks/koalas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,3 +728,13 @@ def test_duplicates(self):

self.assert_eq(pser.drop_duplicates().sort_values(),
kser.drop_duplicates().sort_values())

def test_keys(self):
midx = pd.MultiIndex([['lama', 'cow', 'falcon'],
['speed', 'weight', 'length']],
[[0, 0, 0, 1, 1, 1, 2, 2, 2],
[0, 1, 2, 0, 1, 2, 0, 1, 2]])
kser = ks.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3], index=midx)
pser = kser.to_pandas()

self.assert_eq(kser.keys(), pser.keys())
1 change: 1 addition & 0 deletions docs/source/reference/series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Indexing, iteration
Series.at
Series.loc
Series.iloc
Series.keys

Binary operator functions
-------------------------
Expand Down