Skip to content

Add DataFrame.insert_columns #231

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

Closed
wants to merge 6 commits into from
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions spec/API_specification/dataframe_api/dataframe_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ def get_rows_by_mask(self, mask: Column[Bool]) -> DataFrame:
"""
...

def insert_column(self, column: Column[Any]) -> DataFrame:
def insert_columns(self, columns: Column[Any] | Sequence[Column[Any]]) -> DataFrame:
"""
Insert column into DataFrame at rightmost location.
Insert column(s) into DataFrame at rightmost location.

The column's name will be used as the label in the resulting dataframe.
To insert the column with a different name, combine with `Column.rename`,
Expand All @@ -203,9 +203,22 @@ def insert_column(self, column: Column[Any]) -> DataFrame:
df = df.insert_column(new_column.rename('a_plus_1'))
df = df.get_columns_by_name(new_column_names)

If inserting multiple columns, they must be indepedent.
For example,

.. code-block:: python

new_column_1 = df.get_column_by_name('a').rename('b')
new_column_2 = (new_column_1 + 2).rename('c')
df.insert_columns([new_column_1, new_column_2])

is not allowed, as `new_column_2` depends on `new_column_1`.

Parameters
----------
column : Column
columns : Column | Sequence[Column]
Column(s) to insert. Must be independent of each other, so that insertion
can happen in parallel in some implementations.
"""
...

Expand Down