Skip to content

Commit 45fb1ca

Browse files
committed
fix outdated example
1 parent 97d4dfc commit 45fb1ca

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

spec/API_specification/dataframe_api/dataframe_object.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,52 @@ def insert_column(self, column: Column[Any]) -> DataFrame:
209209
"""
210210
...
211211

212+
def insert_columns(self, columns: Sequence[Column[Any]]) -> DataFrame:
213+
"""
214+
Insert columns into DataFrame at rightmost location.
215+
216+
Like :meth:`insert_column`, but can insert multiple (independent) columns.
217+
Some implementations may be able to make use of parallelism in this
218+
case. For example instead of:
219+
220+
.. code-block::
221+
222+
new_column = df.get_column_by_name('a') + 1
223+
df = df.insert_column(new_column.rename('a_plus_1'))
224+
new_column = df.get_column_by_name('b') + 1
225+
df = df.insert_column(new_column.rename('b_plus_1'))
226+
227+
it would be better to write
228+
229+
.. code-block::
230+
231+
new_column_0 = df.get_column_by_name('a') + 1
232+
new_column_1 = df.get_column_by_name('b') + 1
233+
df = df.insert_columns(
234+
[
235+
new_column_0.rename('a_plus_1'),
236+
new_column_1.rename('b_plus_1'),
237+
]
238+
)
239+
240+
so that insertion can happen in parallel for some implementations.
241+
242+
Parameters
243+
----------
244+
columns : Sequence[Column]
245+
Sequence of `Column`s.
246+
Must be independent of each other.
247+
Column names must be unique.
248+
Column names may not already be present in the
249+
dataframe - use :meth:`Column.rename` to rename them
250+
beforehand if necessary.
251+
252+
Returns
253+
-------
254+
DataFrame
255+
"""
256+
...
257+
212258
def drop_column(self, label: str) -> DataFrame:
213259
"""
214260
Drop the specified column.

0 commit comments

Comments
 (0)