|
17 | 17 | """
|
18 | 18 | Wrappers for Indexes to behave similar to pandas Index, MultiIndex.
|
19 | 19 | """
|
20 |
| - |
21 |
| -from functools import partial, reduce |
| 20 | +from distutils.version import LooseVersion |
| 21 | +from functools import partial |
22 | 22 | from typing import Any, List, Optional, Tuple, Union
|
23 | 23 |
|
24 | 24 | import pandas as pd
|
|
27 | 27 | is_categorical_dtype, is_integer_dtype, is_float_dtype, is_numeric_dtype, is_object_dtype
|
28 | 28 | from pandas.io.formats.printing import pprint_thing
|
29 | 29 |
|
| 30 | +import pyspark |
30 | 31 | from pyspark import sql as spark
|
31 | 32 | from pyspark.sql import functions as F
|
32 | 33 |
|
|
35 | 36 | from databricks.koalas.exceptions import PandasNotImplementedError
|
36 | 37 | from databricks.koalas.base import IndexOpsMixin
|
37 | 38 | from databricks.koalas.frame import DataFrame
|
38 |
| -from databricks.koalas.internal import _InternalFrame |
39 | 39 | from databricks.koalas.missing.indexes import _MissingPandasLikeIndex, _MissingPandasLikeMultiIndex
|
40 | 40 | from databricks.koalas.series import Series
|
41 |
| -from databricks.koalas.utils import name_like_string |
| 41 | +from databricks.koalas.utils import name_like_string, default_session |
42 | 42 | from databricks.koalas.internal import _InternalFrame
|
43 | 43 |
|
44 | 44 |
|
@@ -1159,6 +1159,18 @@ def symmetric_difference(self, other, result_name=None, sort=None):
|
1159 | 1159 |
|
1160 | 1160 | return result
|
1161 | 1161 |
|
| 1162 | + def value_counts(self, normalize=False, sort=True, ascending=False, bins=None, dropna=True): |
| 1163 | + if LooseVersion(pyspark.__version__) < LooseVersion("2.4") and \ |
| 1164 | + default_session().conf.get("spark.sql.execution.arrow.enabled") == "true" and \ |
| 1165 | + isinstance(self, MultiIndex): |
| 1166 | + raise RuntimeError("if you're using pyspark < 2.4, set conf " |
| 1167 | + "'spark.sql.execution.arrow.enabled' to 'false' " |
| 1168 | + "for using this function with MultiIndex") |
| 1169 | + return super(MultiIndex, self).value_counts( |
| 1170 | + normalize=normalize, sort=sort, ascending=ascending, bins=bins, dropna=dropna) |
| 1171 | + |
| 1172 | + value_counts.__doc__ = IndexOpsMixin.value_counts.__doc__ |
| 1173 | + |
1162 | 1174 | def __getattr__(self, item: str) -> Any:
|
1163 | 1175 | if hasattr(_MissingPandasLikeMultiIndex, item):
|
1164 | 1176 | property_or_func = getattr(_MissingPandasLikeMultiIndex, item)
|
|
0 commit comments