Skip to content
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

Fix ungroup spec #1056

Merged
merged 2 commits into from
Jan 16, 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: 4 additions & 1 deletion lib/explorer/data_frame.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5625,7 +5625,10 @@ defmodule Explorer.DataFrame do

"""
@doc type: :single
@spec ungroup(df :: DataFrame.t(), groups_or_group :: column_names() | column_name()) ::
@spec ungroup(
df :: DataFrame.t(),
groups_or_group :: column_names() | column_name() | Range.t() | fun()
) ::
DataFrame.t()
def ungroup(df, groups \\ ..)

Expand Down
11 changes: 11 additions & 0 deletions test/explorer/data_frame/grouped_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ defmodule Explorer.DataFrame.GroupedTest do
assert DF.groups(df2) == []
end

test "ungroup by range", %{df: df} do
df1 = DF.group_by(df, ["country", "year"])
df2 = DF.ungroup(df1, 1..1)

# Note: the range selected the column at index 1 of `df.names` to ungroup,
# not `df.groups`.
assert Enum.take(df.names, 2) == ["year", "country"]
assert df2.groups == ["year"]
assert DF.groups(df2) == ["year"]
end

test "raise error for unknown groups", %{df: df} do
df1 = DF.group_by(df, ["country", "year"])

Expand Down
Loading