Skip to content

Commit

Permalink
Fix bool_only argument functions (#125)
Browse files Browse the repository at this point in the history
* Fixed functions with bool_only arguments

* Fixed formatting

* Fixed any to have same behavior as all and consolidated to have one helper

* formatting

* Fixed default value for any

* Created processing function to keep all and any as attributes of PandasDataFrames
  • Loading branch information
williamma12 authored and devin-petersohn committed Oct 12, 2018
1 parent d2c5e7a commit 6366844
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
35 changes: 27 additions & 8 deletions modin/data_management/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,21 +1116,40 @@ def all(self, **kwargs):
"""Returns whether all the elements are true, potentially over an axis.
Return:
Pandas Series containing boolean values.
Pandas Series containing boolean values or boolean.
"""
axis = kwargs.get("axis", 0)
func = self._prepare_method(pandas.DataFrame.all, **kwargs)
return self.full_axis_reduce(func, axis)
return self._process_all_any(pandas.DataFrame.all, **kwargs)

def any(self, **kwargs):
"""Returns whether any element is true over the requested axis.
"""Returns whether any the elements are true, potentially over an axis.
Return:
Pandas Series containing boolean values or boolean.
"""
return self._process_all_any(pandas.DataFrame.any, **kwargs)

def _process_all_any(self, func, **kwargs):
"""Calculates if any or all the values are true.
Return:
Pandas Series containing boolean values.
Pandas Series containing boolean values or boolean.
"""
axis = kwargs.get("axis", 0)
func = self._prepare_method(pandas.DataFrame.any, **kwargs)
return self.full_axis_reduce(func, axis)
bool_only = kwargs.get("bool_only", None)
index = self.index if axis else self.columns
if bool_only:
not_bool = []
for index, dtype in zip(index, self.dtypes):
if dtype != bool:
not_bool.append(index)
if axis:
data_manager = self.drop(index=not_bool)
else:
data_manager = self.drop(columns=not_bool)
else:
data_manager = self
func = data_manager._prepare_method(func, **kwargs)
return data_manager.full_axis_reduce(func, axis)

def first_valid_index(self):
"""Returns index of first non-NaN/NULL value.
Expand Down
15 changes: 10 additions & 5 deletions modin/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,6 @@ def all(self, axis=0, bool_only=None, skipna=None, level=None, **kwargs):
axis = pandas.DataFrame()._get_axis_number(axis)
else:
axis = None

result = self._data_manager.all(
axis=axis, bool_only=bool_only, skipna=skipna, level=level, **kwargs
)
Expand All @@ -667,18 +666,24 @@ def all(self, axis=0, bool_only=None, skipna=None, level=None, **kwargs):
else:
return result.all()

def any(self, axis=None, bool_only=None, skipna=None, level=None, **kwargs):
def any(self, axis=0, bool_only=None, skipna=None, level=None, **kwargs):
"""Return whether any elements are True over requested axis
Note:
If axis=None or axis=0, this call applies on the column partitions,
otherwise operates on row partitions
"""
axis = pandas.DataFrame()._get_axis_number(axis) if axis is not None else 0

return self._data_manager.any(
if axis is not None:
axis = pandas.DataFrame()._get_axis_number(axis)
else:
axis = None
result = self._data_manager.any(
axis=axis, bool_only=bool_only, skipna=skipna, level=level, **kwargs
)
if axis is not None:
return result
else:
return result.any()

def append(self, other, ignore_index=False, verify_integrity=False, sort=None):
"""Append another DataFrame/list/Series to this one.
Expand Down

0 comments on commit 6366844

Please sign in to comment.