Skip to content

Commit

Permalink
Revert "Add levels property for MultiIndex (#973)"
Browse files Browse the repository at this point in the history
This reverts commit 23dc764.
  • Loading branch information
HyukjinKwon committed Nov 14, 2019
1 parent 96490f1 commit ace0c32
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 42 deletions.
29 changes: 0 additions & 29 deletions databricks/koalas/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,35 +661,6 @@ def __getattr__(self, item: str) -> Any:
def rename(self, name, inplace=False):
raise NotImplementedError()

@property
def levels(self) -> list:
"""
Names of index columns in list.
.. note:: Be aware of the possibility of running into out
of memory issue if returned list is huge.
Examples
--------
>>> mi = pd.MultiIndex.from_arrays((list('abc'), list('def')))
>>> mi.names = ['level_1', 'level_2']
>>> kdf = ks.DataFrame({'a': [1, 2, 3]}, index=mi)
>>> kdf.index.levels
[['a', 'b', 'c'], ['d', 'e', 'f']]
>>> mi = pd.MultiIndex.from_arrays((list('bac'), list('fee')))
>>> mi.names = ['level_1', 'level_2']
>>> kdf = ks.DataFrame({'a': [1, 2, 3]}, index=mi)
>>> kdf.index.levels
[['a', 'b', 'c'], ['e', 'f']]
"""
scols = self._kdf._internal.index_scols
row = self._kdf._sdf.select([F.collect_set(scol) for scol in scols]).first()

# use sorting is because pandas doesn't care the appearance order of level
# names, so e.g. if ['b', 'd', 'a'] will return as ['a', 'b', 'd']
return [sorted(col) for col in row]

def __repr__(self):
max_display_count = get_option("display.max_rows")
if max_display_count is None:
Expand Down
1 change: 1 addition & 0 deletions databricks/koalas/missing/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class _MissingPandasLikeMultiIndex(object):
T = unsupported_property('T')
codes = unsupported_property('codes')
is_all_dates = unsupported_property('is_all_dates')
levels = unsupported_property('levels')
levshape = unsupported_property('levshape')
shape = unsupported_property('shape')

Expand Down
12 changes: 0 additions & 12 deletions databricks/koalas/tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,3 @@ def test_multiindex_from_arrays(self):
kidx = ks.MultiIndex.from_arrays(arrays)

self.assert_eq(pidx, kidx)

def test_multiindex_levels(self):
tuples = [[list('abc'), list('def')], [list('aac'), list('fed')]]

for tup in tuples:
pdf = pd.DataFrame({'a': [1, 2, 3]}, index=tup)
kdf = ks.from_pandas(pdf)

# pandas returns FronzeList, so need to convert it to normal list
# for comparison
pdf_levels = [list(i) for i in pdf.index.levels]
self.assertEqual(pdf_levels, kdf.index.levels)
1 change: 0 additions & 1 deletion docs/source/reference/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ MultiIndex Properties

MultiIndex.names
MultiIndex.ndim
MultiIndex.levels

MultiIndex Modifying and computations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit ace0c32

Please sign in to comment.