Skip to content

Using filter inside summarise raises with an ArgumentError #1115

Description

@billylanchantin

Explorer Issue #1115 (Livebook Contents)

Mix.install([
  {:explorer, "~> 0.11.0"},
  {:kino_pythonx, "~> 0.1.0"},
  {:pythonx, "~> 0.4.2"},
])
[project]
name = "project"
version = "0.0.0"
requires-python = "==3.13.*"
dependencies = [
  "polars==1.32.3"
]

Data

data = %{
  a: [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],
  b: [99, 1, 1, 99, 99, 99, 1, 1, 1, 1, 99, 99]
}
%{a: [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4], b: [99, 1, 1, 99, 99, 99, 1, 1, 1, 1, 99, 99]}

Python

import polars as pl

df_polars = (
    pl.DataFrame(data)
    .group_by(pl.col("a"))
    .agg(pl.col("b").filter(pl.col("b") > 40).mean())
)

df_polars
#Pythonx.Object<
  shape: (4, 2)
  ┌─────┬──────┐
  │ a   ┆ b    │
  │ --- ┆ ---  │
  │ i64 ┆ f64  │
  ╞═════╪══════╡
  │ 3   ┆ 99.0 │
  │ 2   ┆ 99.0 │
  │ 1   ┆ 99.0 │
  │ 4   ┆ 99.0 │
  └─────┴──────┘
>

Elixir

require Explorer.DataFrame, as: DF

df_explorer =
  data
  |> DF.new()
  |> DF.group_by("a")
  |> DF.summarise(b |> filter(_ > 40) |> mean)
** (ArgumentError) expected a variable to be given to var!, got: Explorer.DataFrame.pull(var!(df, Explorer.Query), :df)
    (elixir 1.18.3) expanding macro: Kernel.var!/2
    #cell:pfefn52y4pwggjrl:7: (file)
    (explorer 0.11.0) expanding macro: Explorer.Query.query/1
    #cell:pfefn52y4pwggjrl:7: (file)
    (elixir 1.18.3) expanding macro: Kernel.|>/2
    #cell:pfefn52y4pwggjrl:7: (file)
    (elixir 1.18.3) expanding macro: Kernel.|>/2
    #cell:pfefn52y4pwggjrl:7: (file)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions