Repository: databricks/koalas

Issue:
Series.mode
Implement `Series.mode`.

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.mode.html


Discussion:
Could I try this If it's not so urgent?
Sure, please feel free to go ahead. Thanks!

Resolving patch:
diff --git a/databricks/koalas/missing/series.py b/databricks/koalas/missing/series.py
--- a/databricks/koalas/missing/series.py
+++ b/databricks/koalas/missing/series.py
@@ -79,7 +79,6 @@ class _MissingPandasLikeSeries(object):
     last_valid_index = unsupported_function('last_valid_index')
     mad = unsupported_function('mad')
     mask = unsupported_function('mask')
-    mode = unsupported_function('mode')
     pct_change = unsupported_function('pct_change')
     pop = unsupported_function('pop')
     prod = unsupported_function('prod')
diff --git a/databricks/koalas/series.py b/databricks/koalas/series.py
--- a/databricks/koalas/series.py
+++ b/databricks/koalas/series.py
@@ -3223,6 +3223,89 @@ def copy(self) -> 'Series':
         """
         return _col(DataFrame(self._internal.copy()))
 
+    def mode(self, dropna=True) -> 'Series':
+        """
+        Return the mode(s) of the dataset.
+
+        Always returns Series even if only one value is returned.
+
+        Parameters
+        ----------
+        dropna : bool, default True
+            Don't consider counts of NaN/NaT.
+
+        Returns
+        -------
+        Series
+            Modes of the Series in sorted order.
+
+        Examples
+        --------
+        >>> s = ks.Series([0, 0, 1, 1, 1, np.nan, np.nan, np.nan])
+        >>> s
+        0    0.0
+        1    0.0
+        2    1.0
+        3    1.0
+        4    1.0
+        5    NaN
+        6    NaN
+        7    NaN
+        Name: 0, dtype: float64
+
+        >>> s.mode()
+        0    1.0
+        Name: 0, dtype: float64
+
+        If there are several same modes, all items are shown
+
+        >>> s = ks.Series([0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3,
+        ...                np.nan, np.nan, np.nan])
+        >>> s
+        0     0.0
+        1     0.0
+        2     1.0
+        3     1.0
+        4     1.0
+        5     2.0
+        6     2.0
+        7     2.0
+        8     3.0
+        9     3.0
+        10    3.0
+        11    NaN
+        12    NaN
+        13    NaN
+        Name: 0, dtype: float64
+
+        >>> s.mode()
+        0    1.0
+        1    3.0
+        2    2.0
+        Name: 0, dtype: float64
+
+        With 'dropna' set to 'False', we can also see NaN in the result
+
+        >>> s.mode(False)
+        0    NaN
+        1    1.0
+        2    3.0
+        3    2.0
+        Name: 0, dtype: float64
+        """
+        ser_count = self.value_counts(dropna=dropna, sort=False)
+        sdf_count = ser_count._internal.sdf
+        most_value = ser_count.max()
+        sdf_most_value = sdf_count.where("count == {}".format(most_value))
+        sdf = sdf_most_value.select(
+            F.col(SPARK_INDEX_NAME_FORMAT(0)).alias('0'))
+        internal = _InternalFrame(sdf=sdf)
+
+        result = _col(DataFrame(internal))
+        result.name = self.name
+
+        return result
+
     def keys(self):
         """
         Return alias for index.


Test patch: