Skip to content

Commit

Permalink
Allow accessing the dataframe inside query
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Sep 4, 2024
1 parent 77e0201 commit 49bb939
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/explorer/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/explorer/query_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 49bb939

Please sign in to comment.