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

Add __bool__ function. #1526

Merged
merged 2 commits into from
May 22, 2020
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
6 changes: 6 additions & 0 deletions databricks/koalas/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,12 @@ def compute(self):
"""Alias of `to_pandas()` to mimic dask for easily porting tests."""
return self.toPandas()

def __bool__(self):
raise ValueError(
"The truth value of a {0} is ambiguous. "
"Use a.empty, a.bool(), a.item(), a.any() or a.all().".format(self.__class__.__name__)
)

@staticmethod
def _count_expr(col: spark.Column, spark_type: DataType) -> spark.Column:
# Special handle floating point types because Spark's count treats nan as a valid value,
Expand Down
6 changes: 6 additions & 0 deletions databricks/koalas/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,12 @@ def __xor__(self, other):
def __len__(self):
return self.size

def __bool__(self):
raise ValueError(
"The truth value of a {0} is ambiguous. "
"Use a.empty, a.bool(), a.item(), a.any() or a.all().".format(self.__class__.__name__)
)


class MultiIndex(Index):
"""
Expand Down
7 changes: 4 additions & 3 deletions databricks/koalas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,11 @@ def name_like_string(name: Union[str, Tuple]) -> str:

def validate_axis(axis=0, none_axis=0):
""" Check the given axis is valid. """
if axis not in (0, 1, "index", "columns", None):
raise ValueError("No axis named {0}".format(axis))
# convert to numeric axis
return {None: none_axis, "index": 0, "columns": 1}.get(axis, axis)
axis = {None: none_axis, "index": 0, "columns": 1}.get(axis, axis)
if axis not in (none_axis, 0, 1):
raise ValueError("No axis named {0}".format(axis))
return axis


def validate_bool_kwarg(value, arg_name):
Expand Down