diff --git a/lib/explorer/query.ex b/lib/explorer/query.ex index 7e42b8cae..62d5e1171 100644 --- a/lib/explorer/query.ex +++ b/lib/explorer/query.ex @@ -739,6 +739,11 @@ defmodule Explorer.Query do end end + @doc """ + Returns the dataframe scoped by this query. + """ + defmacro df(), do: df_var() + @doc false def __across__(df, selector) do df diff --git a/test/explorer/query_test.exs b/test/explorer/query_test.exs index b4aeea33e..564e8cdc3 100644 --- a/test/explorer/query_test.exs +++ b/test/explorer/query_test.exs @@ -5,6 +5,12 @@ defmodule Explorer.QueryTest do require Explorer.DataFrame, as: DF doctest Explorer.Query + test "allows accessing the dataframe" do + assert DF.new(a: [1, 2, 3]) + |> DF.filter(df()["a"] < ^if(true, do: 3, else: 1)) + |> DF.to_columns(atom_keys: true) == %{a: [1, 2]} + end + test "allows Kernel operations within pin" do assert DF.new(a: [1, 2, 3]) |> DF.filter(a < ^if(true, do: 3, else: 1))