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

Fix reduction agg with numpy udf #742

Merged
merged 10 commits into from
Oct 16, 2023
11 changes: 10 additions & 1 deletion python/xorbits/_mars/dataframe/reduction/max.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ def is_atomic(self):
return True


def max_series(df, axis=None, skipna=True, level=None, combine_size=None, method=None):
def max_series(
df,
axis=None,
skipna=True,
level=None,
combine_size=None,
method=None,
**kwargs, # kwargs for compatible with numpy reduction
):
op = DataFrameMax(
axis=axis,
skipna=skipna,
Expand All @@ -47,6 +55,7 @@ def max_dataframe(
numeric_only=None,
combine_size=None,
method=None,
**kwargs, # kwargs for compatible with numpy reduction
):
op = DataFrameMax(
axis=axis,
Expand Down
11 changes: 10 additions & 1 deletion python/xorbits/_mars/dataframe/reduction/mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ def mean(x):
return mean


def mean_series(df, axis=None, skipna=True, level=None, combine_size=None, method=None):
def mean_series(
df,
axis=None,
skipna=True,
level=None,
combine_size=None,
method=None,
**kwargs, # kwargs for compatible with numpy reduction
):
op = DataFrameMean(
axis=axis,
skipna=skipna,
Expand All @@ -52,6 +60,7 @@ def mean_dataframe(
numeric_only=None,
combine_size=None,
method=None,
**kwargs, # kwargs for compatible with numpy reduction
):
op = DataFrameMean(
axis=axis,
Expand Down
11 changes: 10 additions & 1 deletion python/xorbits/_mars/dataframe/reduction/min.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ def is_atomic(self):
return True


def min_series(df, axis=None, skipna=True, level=None, combine_size=None, method=None):
def min_series(
df,
axis=None,
skipna=True,
level=None,
combine_size=None,
method=None,
**kwargs, # kwargs for compatible with numpy reduction
):
op = DataFrameMin(
axis=axis,
skipna=skipna,
Expand All @@ -47,6 +55,7 @@ def min_dataframe(
numeric_only=None,
combine_size=None,
method=None,
**kwargs, # kwargs for compatible with numpy reduction
):
op = DataFrameMin(
axis=axis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,27 @@ def realized_volatility(series):
result.execute().fetch(), data.agg(realized_volatility)
)

def trip_type(x):
return np.min(x)

df = md.DataFrame(data)
result = df.agg(trip_type)
pd.testing.assert_series_equal(result.execute().fetch(), data.agg(trip_type))

def trip_type_max(x):
return np.max(x)

df = md.DataFrame(data)
result = df.agg(trip_type_max)
pd.testing.assert_series_equal(result.execute().fetch(), data.agg(trip_type_max))

def trip_type_mean(x):
return np.mean(x)

df = md.DataFrame(data)
result = df.agg(trip_type_mean)
pd.testing.assert_series_equal(result.execute().fetch(), data.agg(trip_type_mean))

df = md.DataFrame(data)
result = df.agg(all_aggs)
pd.testing.assert_frame_equal(result.execute().fetch(), data.agg(all_aggs))
Expand Down
Loading