Skip to content

remove loc from insert_column #239

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 2 commits into from
Aug 28, 2023
Merged
Changes from all 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
24 changes: 16 additions & 8 deletions spec/API_specification/dataframe_api/dataframe_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,31 @@ def get_rows_by_mask(self, mask: Column[Bool]) -> DataFrame:
"""
...

def insert_column(self, loc: int, column: Column[Any]) -> DataFrame:
def insert_column(self, column: Column[Any]) -> DataFrame:
"""
Insert column into DataFrame at specified location.
Insert column 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`,
e.g.:

.. code-block :: python
.. code-block:: python

new_column = df.get_column_by_name('a') + 1
df = df.insert(0, new_column.rename('a_plus_1'))
df = df.insert_column(new_column.rename('a_plus_1'))

If you need to insert the column at a different location, combine with
:meth:`get_columns_by_name`, e.g.:

.. code-block:: python

new_column = df.get_column_by_name('a') + 1
new_columns_names = ['a_plus_1'] + df.get_column_names()
df = df.insert_column(new_column.rename('a_plus_1'))
df = df.get_columns_by_name(new_column_names)

Parameters
----------
loc : int
Insertion index. Must verify 0 <= loc <= len(columns).
column : Column
"""
...
Expand Down Expand Up @@ -235,13 +243,13 @@ def rename_columns(self, mapping: Mapping[str, str]) -> DataFrame:
"""
...

def get_column_names(self) -> Sequence[str]:
def get_column_names(self) -> list[str]:
"""
Get column names.

Returns
-------
Sequence[str]
list[str]
"""
...

Expand Down