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

Updated info and memory_usage to new backend #4

Merged
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
58 changes: 57 additions & 1 deletion modin/data_management/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,27 @@ def idxmin_builder(df, **kwargs):
# have to do a conversion.
return self._post_process_idx_ops(axis, min_result)

def info(self, **kwargs):
def info_builder(df, **kwargs):
result = pandas.DataFrame()
if memory_usage:
result['memory'] = df.memory_usage(index=False, deep=memory_usage_deep)
if null_counts:
result['count'] = df.count(axis=0)
return result

memory_usage = kwargs.get('memory_usage', True)
null_counts = kwargs.get('null_counts', True)

if type(memory_usage) == str and memory_usage == 'deep':
memory_usage_deep = True
else:
memory_usage_deep = False

func = self._prepare_method(info_builder, **kwargs)
return self.full_axis_reduce(func, 0)


def first_valid_index(self):

# It may be possible to incrementally check each partition, but this
Expand Down Expand Up @@ -556,6 +577,14 @@ def median(self, **kwargs):
func = self._prepare_method(pandas.DataFrame.median, **kwargs)
return self.full_axis_reduce(func, axis)

def memory_usage(self, **kwargs):
def memory_usage_builder(df, **kwargs):
return df.memory_usage(index=False, deep=deep)

deep = kwargs.get('deep', False)
func = self._prepare_method(memory_usage_builder, **kwargs)
return self.full_axis_reduce(func, 0)

def nunique(self, **kwargs):
axis = kwargs.get("axis", 0)
func = self._prepare_method(pandas.DataFrame.nunique, **kwargs)
Expand Down Expand Up @@ -599,7 +628,7 @@ def query(self, expr, **kwargs):
cls = type(self)
columns = self.columns

def query_builder(df):
def query_builder(df, **kwargs):
# This is required because of an Arrow limitation
# TODO revisit for Arrow error
df = df.copy()
Expand All @@ -616,6 +645,33 @@ def query_builder(df):

return cls(new_data, new_index, self.columns)

def eval(self, expr, **kwargs):
cls = type(self)
columns = self.columns

def eval_builder(df, **kwargs):
df.columns = columns
result = df.eval(expr, inplace=False, **kwargs)
# If result is a series, expr was not an assignment expression.
if not isinstance(result, pandas.Series):
result.columns = pandas.RangeIndex(0, len(result.columns))
return result

func = self._prepare_method(eval_builder, **kwargs)
new_data = self.map_across_full_axis(1, func)

# eval can update the columns, so we must update columns
columns_copy = pandas.DataFrame(columns=columns)
columns_copy = columns_copy.eval(expr, inplace=False, **kwargs)
if isinstance(columns_copy, pandas.Series):
# To create a data manager, we need the
# columns to be in a list-like
columns = list(columns_copy.name)
else:
columns = columns_copy.columns

return cls(new_data, self.index, columns)

def quantile_for_list_of_values(self, **kwargs):
cls = type(self)
axis = kwargs.get("axis", 0)
Expand Down
Loading