Skip to content

Commit

Permalink
Support callables in DataFrame.assign
Browse files Browse the repository at this point in the history
  • Loading branch information
wence- committed Sep 20, 2023
1 parent 7b0693f commit bdc1444
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1407,13 +1407,15 @@ def assign(self, **kwargs):
"""
new_df = cudf.DataFrame(index=self.index.copy())
for name, col in self._data.items():
if name in kwargs:
new_df[name] = kwargs.pop(name)
else:
# Copy non-overwritten kwargs
if name not in kwargs:
new_df._data[name] = col.copy()

for k, v in kwargs.items():
new_df[k] = v
if callable(v):
new_df[k] = v(new_df)
else:
new_df[k] = v
return new_df

@classmethod
Expand Down

0 comments on commit bdc1444

Please sign in to comment.