Skip to content

Commit

Permalink
Fix unique to support multi-index columns.
Browse files Browse the repository at this point in the history
  • Loading branch information
ueshin committed Sep 20, 2019
1 parent 1bf41b8 commit 76da3ce
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions databricks/koalas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,8 @@ def unique(self):
Examples
--------
>>> ks.Series([2, 1, 3, 3], name='A').unique()
>>> kser = ks.Series([2, 1, 3, 3], name='A')
>>> kser.unique()
0 1
1 3
2 2
Expand All @@ -1506,9 +1507,20 @@ def unique(self):
>>> ks.Series([pd.Timestamp('2016-01-01') for _ in range(3)]).unique()
0 2016-01-01
Name: 0, dtype: datetime64[ns]
>>> kser.name = ('x', 'a')
>>> kser.unique()
0 1
1 3
2 2
Name: (x, a), dtype: int64
"""
sdf = self.to_dataframe()._sdf
return _col(DataFrame(sdf.select(self._scol).distinct()))
sdf = self._internal.sdf.select(self._scol).distinct()
internal = _InternalFrame(sdf=sdf,
data_columns=[self._internal.data_columns[0]],
column_index=[self._internal.column_index[0]],
column_index_names=self._internal.column_index_names)
return _col(DataFrame(internal))

def nunique(self, dropna: bool = True, approx: bool = False, rsd: float = 0.05) -> int:
"""
Expand Down

0 comments on commit 76da3ce

Please sign in to comment.