Skip to content
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e7e78ce
Added type checking and changed how variables were read in from kwargs
williamma12 Aug 29, 2018
d686848
Merge branch 'rewrite_backend' into rewrite_backend
devin-petersohn Aug 30, 2018
cf9b05d
Updated sample to new architecture
williamma12 Aug 30, 2018
2b94c77
Fixed merge conflict
williamma12 Aug 30, 2018
8724956
Made test_sample more rigourous
williamma12 Aug 31, 2018
2ad1c3b
Removed 'default=' from kwargs.get's
williamma12 Aug 31, 2018
502bd0d
Updated eval to the new backend
williamma12 Aug 31, 2018
992a8e2
Added two more tests for eval
williamma12 Aug 31, 2018
7cbb17a
Updated memory_usage to new backend
williamma12 Sep 1, 2018
b144b3d
Updated info and memory_usage to the new backend
williamma12 Sep 2, 2018
4e7adda
Updated info and memory_usage to be standalone tests and updated the …
williamma12 Sep 2, 2018
8a69de5
Updated info to do only one pass
williamma12 Sep 2, 2018
0ea925f
Updated info to do everything in one run with DataFrame
williamma12 Sep 2, 2018
8a7b320
Update info to do everything in one run with Series
williamma12 Sep 2, 2018
8585f8f
Updated info to do everything in one run with DataFrame
williamma12 Sep 2, 2018
e273288
Updated to get everything working and moved appropriate parts to Data…
williamma12 Sep 2, 2018
9d0f224
Fixed merge conflics
williamma12 Sep 2, 2018
5d52f7f
Removed extraneous print statement
williamma12 Sep 6, 2018
7571b3d
Moved dtypes stuff to data manager
williamma12 Sep 6, 2018
e70aaec
Fixed calculating dtypes to only doing a full_reduce instead of map_f…
williamma12 Sep 6, 2018
2d3a0a5
Merge branch 'data_manager_dtypes' into rewrite_backend
williamma12 Sep 6, 2018
59d6c41
Updated astype to new backend
williamma12 Sep 7, 2018
f53917f
Updated astype to new backend
williamma12 Sep 7, 2018
e1b01fc
Updated ftypes to new backend
williamma12 Sep 7, 2018
3c28c8f
Added dtypes argument to map_partitions
williamma12 Sep 7, 2018
f6a8ed6
Merge branch 'rewrite_backend' into rewrite_backend
williamma12 Sep 7, 2018
c48c861
Updated astype and added dtypes option to _from_old_block_partitions …
williamma12 Sep 7, 2018
de9bc00
Fixed merge conflict
williamma12 Sep 7, 2018
a47f8be
Undid unnecessary change
williamma12 Sep 7, 2018
39d8330
Merge branch 'rewrite_backend' of https://github.com/devin-petersohn/…
williamma12 Sep 7, 2018
9c38231
Updated iterables to new backend
williamma12 Sep 8, 2018
c8b6301
Updated to_datetime to new backend
williamma12 Sep 10, 2018
a9af405
Reverted some changes for PR
williamma12 Sep 10, 2018
7e3c03d
Replaced pd with pandas
williamma12 Sep 10, 2018
ebea577
Made additional changes mentioned in (#7)
williamma12 Sep 10, 2018
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
89 changes: 47 additions & 42 deletions modin/data_management/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy as np
import pandas

from pandas.compat import string_types
from pandas.core.dtypes.cast import find_common_type
from pandas.core.dtypes.common import (_get_dtype_from_object, is_list_like)
Expand Down Expand Up @@ -193,7 +194,7 @@ def _append_data_manager(self, other, ignore_index):
new_data = new_self.concat(0, to_append)
new_index = self.index.append(other.index) if not ignore_index else pandas.RangeIndex(len(self.index) + len(other.index))

return cls(new_data, new_index, joined_columns)
return cls(new_data, new_index, joined_columns, None)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove None


def _append_list_of_managers(self, others, ignore_index):
assert isinstance(others, list), \
Expand All @@ -210,7 +211,7 @@ def _append_list_of_managers(self, others, ignore_index):
new_data = new_self.concat(0, to_append)
new_index = self.index.append([other.index for other in others]) if not ignore_index else pandas.RangeIndex(len(self.index) + sum([len(other.index) for other in others]))

return cls(new_data, new_index, joined_columns)
return cls(new_data, new_index, joined_columns, None)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove None


def _join_data_manager(self, other, **kwargs):
assert isinstance(other, type(self)), \
Expand All @@ -236,7 +237,7 @@ def _join_data_manager(self, other, **kwargs):
other_proxy = pandas.DataFrame(columns=other.columns)
new_columns = self_proxy.join(other_proxy, lsuffix=lsuffix, rsuffix=rsuffix).columns

return cls(new_data, joined_index, new_columns)
return cls(new_data, joined_index, new_columns, None)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove None, there are several more, please make sure they are removed.


def _join_list_of_managers(self, others, **kwargs):
assert isinstance(others, list), \
Expand Down Expand Up @@ -270,8 +271,8 @@ def _join_list_of_managers(self, others, **kwargs):
others_proxy = [pandas.DataFrame(columns=other.columns) for other in others]
new_columns = self_proxy.join(others_proxy, lsuffix=lsuffix, rsuffix=rsuffix).columns

return cls(new_data, joined_index, new_columns)
# END Append/Concat/Join
return cls(new_data, joined_index, new_columns, None)
# END Append/Concat/Join (Not Merge)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this change.


# Inter-Data operations (e.g. add, sub)
# These operations require two DataFrames and will change the shape of the
Expand Down Expand Up @@ -306,7 +307,7 @@ def inter_data_op_builder(left, right, self_cols, other_cols, func):

new_data = reindexed_self.inter_data_operation(1, lambda l, r: inter_data_op_builder(l, r, self_cols, other_cols, func), reindexed_other)

return cls(new_data, joined_index, new_columns)
return cls(new_data, joined_index, new_columns, None)

def _inter_df_op_handler(self, func, other, **kwargs):
"""Helper method for inter-DataFrame and scalar operations"""
Expand Down Expand Up @@ -354,7 +355,7 @@ def where_builder_series(df, cond, other, **kwargs):
reindexed_cond = cond.reindex(axis, self.index if not axis else self.columns).data

new_data = reindexed_self.inter_data_operation(axis, lambda l, r: where_builder_series(l, r, other, **kwargs), reindexed_cond)
return cls(new_data, self.index, self.columns)
return cls(new_data, self.index, self.columns, None)

def update(self, other, **kwargs):
assert isinstance(other, type(self)), \
Expand Down Expand Up @@ -480,7 +481,7 @@ def reset_index(self, **kwargs):
new_column_name = "index" if "index" not in self.columns else "level_0"
new_columns = self.columns.insert(0, new_column_name)
result = self.insert(0, new_column_name, self.index)
return cls(result.data, new_index, new_columns)
return cls(result.data, new_index, new_columns, None)
else:
# The copies here are to ensure that we do not give references to
# this object for the purposes of updates.
Expand All @@ -504,7 +505,7 @@ def transpose(self, *args, **kwargs):
cls = type(self)
new_data = self.data.transpose(*args, **kwargs)
# Switch the index and columns and transpose the
new_manager = cls(new_data, self.columns, self.index)
new_manager = cls(new_data, self.columns, self.index, None)
# It is possible that this is already transposed
new_manager._is_transposed = self._is_transposed ^ 1
return new_manager
Expand Down Expand Up @@ -758,6 +759,14 @@ def std(self, **kwargs):
func = self._prepare_method(pandas.DataFrame.std, **kwargs)
return self.full_axis_reduce(func, axis)

def to_datetime(self, **kwargs):
columns = self.columns
def to_datetime_builder(df, **kwargs):
df.columns = columns
return pandas.to_datetime(df, **kwargs)
func = self._prepare_method(to_datetime_builder, **kwargs)
return self.full_axis_reduce(func, 1)

def var(self, **kwargs):
# Pandas default is 0 (though not mentioned in docs)
axis = kwargs.get("axis", 0)
Expand Down Expand Up @@ -843,7 +852,7 @@ def quantile_for_list_of_values(self, **kwargs):

new_data = self.map_across_full_axis(axis, func)
new_columns = self.columns if not axis else self.index
return cls(new_data, q_index, new_columns)
return cls(new_data, q_index, new_columns, None)

def _cumulative_builder(self, func, **kwargs):
cls = type(self)
Expand Down Expand Up @@ -947,7 +956,7 @@ def fillna_dict_builder(df, func_dict={}):
else:
func = self._prepare_method(pandas.DataFrame.fillna, **kwargs)
new_data = self.map_across_full_axis(axis, func)
return cls(new_data, self.index, self.columns)
return cls(new_data, self.index, self.columns, None)

def describe(self, **kwargs):
cls = type(self)
Expand All @@ -957,8 +966,9 @@ def describe(self, **kwargs):
new_data = self.map_across_full_axis(axis, func)
new_index = self.compute_index(0, new_data, False)
new_columns = self.compute_index(1, new_data, True)
new_dtypes = pd.Series([np.float64 for _ in new_columns], index=new_columns)

return cls(new_data, new_index, new_columns)
return cls(new_data, new_index, new_columns, new_dtypes)

def rank(self, **kwargs):
cls = type(self)
Expand All @@ -974,7 +984,7 @@ def rank(self, **kwargs):
new_columns = self.compute_index(1, new_data, True)
else:
new_columns = self.columns
new_dtypes = pandas.Series([np.float64 for _ in new_columns], index=new_columns)
new_dtypes = pd.Series([np.float64 for _ in new_columns], index=new_columns)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this back.

return cls(new_data, self.index, new_columns, new_dtypes)

def diff(self, **kwargs):
Expand All @@ -985,7 +995,7 @@ def diff(self, **kwargs):
func = self._prepare_method(pandas.DataFrame.diff, **kwargs)
new_data = self.map_across_full_axis(axis, func)

return cls(new_data, self.index, self.columns)
return cls(new_data, self.index, self.columns, None)
# END Map across rows/columns

# Head/Tail/Front/Back
Expand Down Expand Up @@ -1062,7 +1072,7 @@ def from_pandas(cls, df, block_partitions_cls):
df.columns = pandas.RangeIndex(len(df.columns))
new_data = block_partitions_cls.from_pandas(df)

return cls(new_data, new_index, new_columns, new_dtypes)
return cls(new_data, new_index, new_columns, dtypes=new_dtypes)

# __getitem__ methods
def getitem_single_key(self, key):
Expand Down Expand Up @@ -1143,8 +1153,9 @@ def delitem(df, internal_indices=[]):
# We can't use self.columns.drop with duplicate keys because in Pandas
# it throws an error.
new_columns = [self.columns[i] for i in range(len(self.columns)) if i not in numeric_indices]
new_dtypes = self.dtypes.drop(columns)

dtypes = dtypes.values

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be reverted. It is causing errors in the tests.

new_dtypes = pd.Series([dtypes[i] for i in range(len(dtypes)) if i not in numeric_indices])
new_dtypes.index = new_columns
return cls(new_data, new_index, new_columns, new_dtypes)
# END __delitem__ and drop

Expand All @@ -1163,42 +1174,37 @@ def insert(df, internal_indices=[]):

new_data = self.data.apply_func_to_select_indices_along_full_axis(0, insert, loc, keep_remaining=True)
new_columns = self.columns.insert(loc, column)

# Because a Pandas Series does not allow insert, we make a DataFrame
# and insert the new dtype that way.
temp_dtypes = pandas.DataFrame(self.dtypes).T
temp_dtypes.insert(loc, column, _get_dtype_from_object(value))
new_dtypes = temp_dtypes.iloc[0]

new_dtypes = self.dtypes.insert(loc, _get_dtype_from_object(value))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be reverted. It is causing errors in the tests.

return cls(new_data, self.index, new_columns, new_dtypes)
# END Insert

# astype
# This method changes the types of select columns to the new dtype.
# This method change the dtypes of column(s)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# This method changes the dtypes of column(s).

def astype(self, col_dtypes, errors='raise', **kwargs):
cls = type(self)

# Group the indicies to update together and create new dtypes series
dtype_indices = dict()
columns = col_dtypes.keys()
new_dtypes = self.dtypes.copy()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add these back? They make the code more readable.

numeric_indices = list(self.columns.get_indexer_for(columns))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add these back? They make the code more readable.

for i, column in enumerate(columns):
dtype = col_dtypes[column]
if dtype in dtype_indices.keys():
dtype_indices[dtype].append(numeric_indices[i])
else:
dtype_indices[dtype] = [numeric_indices[i]]
new_dtype = np.dtype(dtype)
if dtype != np.int32 and new_dtype == np.int32:
new_dtype = np.dtype('int64')
elif dtype != np.float32 and new_dtype == np.float32:
new_dtype = np.dtype('float64')
new_dtypes[column] = new_dtype

if dtype != self.dtypes[column]:
if dtype in dtype_indices.keys():
dtype_indices[dtype].append(numeric_indices[i])
else:
dtype_indices[dtype] = [numeric_indices[i]]
new_dtype = np.dtype(dtype)
if dtype != np.int32 and new_dtype == np.int32:
new_dtype = np.dtype('int64')
elif dtype != np.float32 and new_dtype == np.float32:
new_dtype = np.dtype('float64')
new_dtypes[column] = new_dtype

new_data = self.data
for dtype in dtype_indices.keys():
resulting_dtype = None

def astype(df, internal_indices=[]):
block_dtypes = dict()
Expand All @@ -1208,8 +1214,8 @@ def astype(df, internal_indices=[]):

new_data = self.data.apply_func_to_select_indices(0, astype, dtype_indices[dtype], keep_remaining=True)

return cls(self.data, self.index, self.columns, new_dtypes)
# END astype
return cls(new_data, self.index, self.columns, new_dtypes)
# END type conversions

# UDF (apply and agg) methods
# There is a wide range of behaviors that are supported, so a lot of the
Expand Down Expand Up @@ -1248,7 +1254,7 @@ def _post_process_apply(self, result_data, axis):
series_result.index = index
return series_result

return cls(result_data, index, columns)
return cls(result_data, index, columns, None)

def _dict_func(self, func, axis, *args, **kwargs):
if "axis" not in kwargs:
Expand Down Expand Up @@ -1302,7 +1308,6 @@ def callable_apply_builder(df, func, axis, index, *args, **kwargs):

func_prepared = self._prepare_method(lambda df: callable_apply_builder(df, func, axis, index, *args, **kwargs))
result_data = self.map_across_full_axis(axis, func_prepared)

return self._post_process_apply(result_data, axis)
# END UDF

Expand Down
Loading