Skip to content

Commit

Permalink
fix: dataframe sort_values Series input keyerror. (#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
Genesis929 authored Jan 14, 2025
1 parent dc92e95 commit 5a2731b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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

0 comments on commit 5a2731b

Please sign in to comment.