Skip to content

Add DataFrame.unique_indices #194

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 3 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion spec/API_specification/dataframe_api/column_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def unique_indices(self, *, skip_nulls: bool = True) -> Column[int]:
indices corresponding to the same unique value, there is no guarantee
about which one will appear in the result.
If the original Column contains multiple `'NaN'` values, then
only a single index corresponding to those values should be returned.
only a single index corresponding to those values will be returned.
Likewise for null values (if ``skip_nulls=False``).
To get the unique values, you can do ``col.get_rows(col.unique_indices())``.
"""
Expand Down
21 changes: 21 additions & 0 deletions spec/API_specification/dataframe_api/dataframe_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,27 @@ def is_nan(self) -> DataFrame:
"""
...

def unique_indices(self, keys: Sequence[str], *, skip_nulls: bool = True) -> Column[int]:
"""
Return indices corresponding to unique values across selected columns.

Returns
-------
Column[int]
Indices corresponding to unique values.

Notes
-----
There are no ordering guarantees. In particular, if there are multiple
indices corresponding to the same unique value(s), there is no guarantee
about which one will appear in the result.
If the original column(s) contain multiple `'NaN'` values, then
only a single index corresponding to those values will be returned.
Likewise for null values (if ``skip_nulls=False``).
To get the unique values, you can do ``df.get_rows(df.unique_indices(keys))``.
"""
...

def fill_nan(self, value: float | 'null', /) -> DataFrame:
"""
Fill ``nan`` values with the given fill value.
Expand Down