Skip to content

Commit

Permalink
Fix ungroup spec (#1056)
Browse files Browse the repository at this point in the history
* Add more to the ungroup spec

I believe this fixes dialyzer's warning.

* Add a test to clarify how ranges in ungroup work
  • Loading branch information
billylanchantin authored Jan 16, 2025
1 parent cc13d20 commit 1095bcb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit 1095bcb

Please sign in to comment.