Skip to content
51 changes: 40 additions & 11 deletions python/ray/dataframe/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,8 @@ def groupby(self, by=None, axis=0, level=None, as_index=True, sort=True,
return DataFrameGroupBy(self, by, axis, level, as_index, sort,
group_keys, squeeze, **kwargs)

def sum(self, axis=None, skipna=True, level=None, numeric_only=None):
def sum(self, axis=None, skipna=True, level=None, numeric_only=None,
min_count=1, **kwargs):
"""Perform a sum across the DataFrame.

Args:
Expand All @@ -616,7 +617,8 @@ def sum(self, axis=None, skipna=True, level=None, numeric_only=None):
"""
def remote_func(df):
return df.sum(axis=axis, skipna=skipna, level=level,
numeric_only=numeric_only)
numeric_only=numeric_only, min_count=min_count,
**kwargs)

return self._arithmetic_helper(remote_func, axis, level)

Expand Down Expand Up @@ -2740,16 +2742,43 @@ def pow(self, other, axis='columns', level=None, fill_value=None):
fill_value)

def prod(self, axis=None, skipna=None, level=None, numeric_only=None,
min_count=0, **kwargs):
raise NotImplementedError(
"To contribute to Pandas on Ray, please visit "
"github.com/ray-project/ray.")
min_count=1, **kwargs):
"""Return the product of the values for the requested axis

Args:
axis : {index (0), columns (1)}
skipna : boolean, default True
level : int or level name, default None
numeric_only : boolean, default None
min_count : int, default 1

Returns:
prod : Series or DataFrame (if level specified)
"""
def remote_func(df):
return df.prod(axis=axis, skipna=skipna, level=level,
numeric_only=numeric_only, min_count=min_count,
**kwargs)

return self._arithmetic_helper(remote_func, axis, level)

def product(self, axis=None, skipna=None, level=None, numeric_only=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Pandas defines product as an alias of prod, so we should do the same.

min_count=0, **kwargs):
raise NotImplementedError(
"To contribute to Pandas on Ray, please visit "
"github.com/ray-project/ray.")
min_count=1, **kwargs):
"""Return the product of the values for the requested axis

Args:
axis : {index (0), columns (1)}
skipna : boolean, default True
level : int or level name, default None
numeric_only : boolean, default None
min_count : int, default 1

Returns:
product : Series or DataFrame (if level specified)
"""
return self.prod(axis=axis, skipna=skipna, level=level,
numeric_only=numeric_only, min_count=min_count,
**kwargs)

def quantile(self, q=0.5, axis=0, numeric_only=True,
interpolation='linear'):
Expand Down Expand Up @@ -4424,4 +4453,4 @@ def _merge_columns(left_columns, right_columns, *args):
"""
return pd.DataFrame(columns=left_columns, index=[0], dtype='uint8').merge(
pd.DataFrame(columns=right_columns, index=[0], dtype='uint8'),
*args).columns
*args).columns
Copy link
Member

Choose a reason for hiding this comment

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

Please replace newline.

21 changes: 11 additions & 10 deletions python/ray/dataframe/test/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def test_int_dataframe():

test_copy(ray_df)
test_sum(ray_df, pandas_df)
test_prod(ray_df, pandas_df)
test_product(ray_df, pandas_df)
test_abs(ray_df, pandas_df)
test_keys(ray_df, pandas_df)
test_transpose(ray_df, pandas_df)
Expand Down Expand Up @@ -367,6 +369,8 @@ def test_float_dataframe():

test_copy(ray_df)
test_sum(ray_df, pandas_df)
test_prod(ray_df, pandas_df)
test_product(ray_df, pandas_df)
test_abs(ray_df, pandas_df)
test_keys(ray_df, pandas_df)
test_transpose(ray_df, pandas_df)
Expand Down Expand Up @@ -2205,18 +2209,14 @@ def test_pow():
test_inter_df_math("pow", simple=False)


def test_prod():
ray_df = create_test_dataframe()

with pytest.raises(NotImplementedError):
ray_df.prod(None)

@pytest.fixture
def test_prod(ray_df, pandas_df):
assert(ray_df_equals_pandas(ray_df.prod(), pandas_df.prod()))

def test_product():
ray_df = create_test_dataframe()

with pytest.raises(NotImplementedError):
ray_df.product()
@pytest.fixture
def test_product(ray_df, pandas_df):
assert(ray_df_equals_pandas(ray_df.product(), pandas_df.product()))


@pytest.fixture
Expand Down Expand Up @@ -3105,3 +3105,4 @@ def test__doc__():
pd_obj = getattr(pd.DataFrame, attr, None)
if callable(pd_obj) or isinstance(pd_obj, property):
assert obj.__doc__ == pd_obj.__doc__

Copy link
Member

Choose a reason for hiding this comment

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

Please replace newline.