Skip to content

fix: dataframe sort_values Series input now raises keyerror. #1285

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
Jan 14, 2025
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
5 changes: 5 additions & 0 deletions bigframes/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,11 @@ def sort_values(
kind: str = "quicksort",
na_position: typing.Literal["first", "last"] = "last",
) -> DataFrame:
if isinstance(by, (bigframes.series.Series, indexes.Index, DataFrame)):
raise KeyError(
f"Invalid key type: {type(by).__name__}. Please provide valid column name(s)."
)

if na_position not in {"first", "last"}:
raise ValueError("Param na_position must be one of 'first' or 'last'")

Expand Down
5 changes: 5 additions & 0 deletions tests/system/small/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,11 @@ def test_dataframe_sort_values(
)


def test_dataframe_sort_values_invalid_input(scalars_df_index):
with pytest.raises(KeyError):
scalars_df_index.sort_values(by=scalars_df_index["int64_col"])


def test_dataframe_sort_values_stable(scalars_df_index, scalars_pandas_df_index):
bf_result = (
scalars_df_index.sort_values("int64_col", kind="stable")
Expand Down
Loading