Skip to content

Commit 898889c

Browse files
Fix apply when args is set (#953)
* Resolves #915 * Send `args` as another keyword argument instead of unpacking the tuple * Add tests to verify correctness of fixed functionality
1 parent 9823016 commit 898889c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

modin/pandas/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def apply(
561561
)
562562
elif not callable(func) and not is_list_like(func):
563563
raise TypeError("{} object is not callable".format(type(func)))
564-
query_compiler = self._query_compiler.apply(func, axis, *args, **kwds)
564+
query_compiler = self._query_compiler.apply(func, axis, args=args, **kwds)
565565
return query_compiler
566566

567567
def as_blocks(self, copy=True):

modin/pandas/test/test_dataframe.py

+20
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,26 @@ def test_apply(self, request, data, func, axis):
10701070
modin_result = modin_df.apply(func, axis)
10711071
df_equals(modin_result, pandas_result)
10721072

1073+
@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
1074+
@pytest.mark.parametrize("axis", axis_values, ids=axis_keys)
1075+
def test_apply_args(self, data, axis):
1076+
modin_df = pd.DataFrame(data)
1077+
pandas_df = pandas.DataFrame(data)
1078+
1079+
def apply_func(series, y):
1080+
try:
1081+
return series + y
1082+
except TypeError:
1083+
return series.map(str) + str(y)
1084+
1085+
modin_result = modin_df.apply(apply_func, axis=axis, args=(1,))
1086+
pandas_result = pandas_df.apply(apply_func, axis=axis, args=(1,))
1087+
df_equals(modin_result, pandas_result)
1088+
1089+
modin_result = modin_df.apply(apply_func, axis=axis, args=("_A",))
1090+
pandas_result = pandas_df.apply(apply_func, axis=axis, args=("_A",))
1091+
df_equals(modin_result, pandas_result)
1092+
10731093
def test_apply_metadata(self):
10741094
def add(a, b, c):
10751095
return a + b + c

0 commit comments

Comments
 (0)