8000 Add DataFrame.update_columns by MarcoGorelli · Pull Request #232 · data-apis/dataframe-api · GitHub
[go: up one dir, main page]

Skip to content

Add DataFrame.update_columns #232

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

Merged
Merged
Changes from 1 commit
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
61 changes: 61 additions & 0 deletions spec/API_specification/dataframe_api/dataframe_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,67 @@ def insert_column(self, loc: int, column: Column[Any]) -> DataFrame:
"""
...

def update_column(self, column: Column[Any]) -> DataFrame:
"""
Update column in DataFrame.

The column's name must already be present in the dataframe.

Parameters
----------
column : Column

Returns
-------
DataFrame
"""
...

def update_columns(self, columns: Sequence[Column[Any]]) -> DataFrame:
"""
Update values in existing columns.

Like :meth:`update_column`, but can update multiple (independent) columns.
Some implementations may be able to make use of parallelism in this
case. For example instead of:

.. code-block:: python

new_column = df.get_column_by_name('a') + 1
df = df.update_column(new_column)
new_column = df.get_column_by_name('b') + 1
df = df.update_column(new_column)

it would be better to write

.. code-block:: python

new_column_0 = df.get_column_by_name('a') + 1
new_column_1 = df.get_column_by_name('b') + 1
df = df.update_columns(
[
new_column_0,
new_column_1,
]
)

so that updates can happen in parallel for some implementations.

Parameters
----------
columns : Sequence[Column]
Sequence of columns.
Must be independent of each other.
Column names must already be present in dataframe - use
:meth:`Column.rename` to rename them
beforehand if necessary.

Returns
-------
DataFrame
"""
...

def drop_column(self, label: str) -> DataFrame:
"""
Drop the specified column.
Expand Down
0