Skip to content

Commit

Permalink
Validation for groupby arguments (#4176)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Jul 29, 2022
1 parent 992da40 commit 29598cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions py-polars/polars/internals/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3104,6 +3104,10 @@ def groupby(
└─────┴─────┴─────┘
"""
if not isinstance(maintain_order, bool):
raise TypeError(
f"invalid input for groupby arg `maintain_order`: {maintain_order}."
)
if isinstance(by, str):
by = [by]
return GroupBy(
Expand Down
4 changes: 4 additions & 0 deletions py-polars/tests/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ def test_groupby() -> None:
# assert df.groupby("b").quantile(0.5).shape == (2, 3)
assert df.groupby("b").agg_list().shape == (2, 3)

# Invalid input: `by` not specified as a sequence
with pytest.raises(TypeError):
df.groupby("a", "b") # type: ignore[arg-type]


@pytest.mark.parametrize(
"stack,exp_shape,exp_columns",
Expand Down

0 comments on commit 29598cc

Please sign in to comment.