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 product for lazy series #986

Merged
merged 1 commit into from
Sep 13, 2024
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
2 changes: 1 addition & 1 deletion lib/explorer/backend/lazy_series.ex
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ defmodule Explorer.Backend.LazySeries do
do: {:u, 32}

defp dtype_for_agg_operation(op, series)
when op in [:first, :last, :sum, :min, :max],
when op in [:first, :last, :sum, :min, :max, :product],
do: series.dtype

defp dtype_for_agg_operation(op, _) when op in [:all?, :any?], do: :boolean
Expand Down
2 changes: 1 addition & 1 deletion lib/explorer/polars_backend/series.ex
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ defmodule Explorer.PolarsBackend.Series do
do: Shared.apply_series(series, :s_quantile, [quantile, "nearest"])

@impl true
def product(series), do: Shared.apply_series(series, :s_product)
def product(series), do: first(Shared.apply_series(series, :s_product))

@impl true
def skew(series, bias?),
Expand Down
2 changes: 1 addition & 1 deletion lib/explorer/series.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,7 @@ defmodule Explorer.Series do
@doc type: :aggregation
@spec product(series :: Series.t()) :: float() | non_finite() | nil
def product(%Series{dtype: dtype} = series) when is_numeric_dtype(dtype),
do: at(apply_series(series, :product), 0)
do: apply_series(series, :product)

def product(%Series{dtype: dtype}),
do: dtype_error("product/1", dtype, @numeric_dtypes)
Expand Down
15 changes: 15 additions & 0 deletions test/explorer/data_frame_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4167,6 +4167,21 @@ defmodule Explorer.DataFrameTest do
assert b in [2, 3]
end

test "product/1 without groups (see grouped_test for groups)" do
df = DF.new(petal_width: [1, 2, 2, 3, 3, 120])

df1 =
DF.summarise(df, petal_width_product: product(petal_width))

assert DF.dtypes(df1) == %{
"petal_width_product" => {:s, 64}
}

result = DF.to_columns(df1)

assert result["petal_width_product"] == [4320]
end

test "argmax/1 and argmin/1" do
df =
DF.new(
Expand Down
Loading