Skip to content

Commit 5099086

Browse files
authored
update/insert columns -> assign (#269)
* update/insert columns -> with_columns * with_columns -> assign
1 parent ecdfcfe commit 5099086

File tree

2 files changed

+11
-37
lines changed

2 files changed

+11
-37
lines changed

spec/API_specification/dataframe_api/dataframe_object.py

+10-36
Original file line numberDiff line numberDiff line change
@@ -179,53 +179,27 @@ def filter(self, mask: Column) -> DataFrame:
179179
"""
180180
...
181181

182-
def insert_column(self, column: Column) -> DataFrame:
182+
def assign(self, columns: Column | Sequence[Column], /) -> DataFrame:
183183
"""
184-
Insert column into DataFrame at rightmost location.
184+
Insert new column(s), or update values in existing ones.
185185
186-
The column's name will be used as the label in the resulting dataframe.
187-
To insert the column with a different name, combine with `Column.rename`,
188-
e.g.:
186+
If inserting new columns, the column's names will be used as the labels,
187+
and the columns will be inserted at the rightmost location.
189188
190-
.. code-block:: python
191-
192-
new_column = df.get_column_by_name('a') + 1
193-
df = df.insert_column(new_column.rename('a_plus_1'))
194-
195-
If you need to insert the column at a different location, combine with
196-
:meth:`select`, e.g.:
197-
198-
.. code-block:: python
199-
200-
new_column = df.get_column_by_name('a') + 1
201-
new_columns_names = ['a_plus_1'] + df.column_names
202-
df = df.insert_column(new_column.rename('a_plus_1'))
203-
df = df.select(new_column_names)
204-
205-
Parameters
206-
----------
207-
column : Column
208-
"""
209-
...
210-
211-
def update_columns(self, columns: Column | Sequence[Column], /) -> DataFrame:
212-
"""
213-
Update values in existing column(s) from Dataframe.
214-
215-
The column's name will be used to tell which column to update.
216-
To update a column with a different name, combine with :meth:`Column.rename`,
217-
e.g.:
189+
If updating existing columns, their names will be used to tell which columns
190+
to update. To update a column with a different name, combine with
191+
:meth:`Column.rename`, e.g.:
218192
219193
.. code-block:: python
220194
221195
new_column = df.get_column_by_name('a') + 1
222-
df = df.update_column(new_column.rename('b'))
196+
df = df.assign(new_column.rename('b'))
223197
224198
Parameters
225199
----------
226200
columns : Column | Sequence[Column]
227-
Column(s) to update. If updating multiple columns, they must all have
228-
different names.
201+
Column(s) to update/insert. If updating/inserting multiple columns,
202+
they must all have different names.
229203
230204
Returns
231205
-------

spec/purpose_and_scope.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def my_dataframe_agnostic_function(df):
296296
continue
297297
new_column = df.get_column_by_name(column_name)
298298
new_column = (new_column - new_column.mean()) / new_column.std()
299-
df = df.insert_column(new_column.rename(f'{column_name}_scaled'))
299+
df = df.assign(new_column.rename(f'{column_name}_scaled'))
300300

301301
return df.dataframe
302302

0 commit comments

Comments
 (0)