Skip to content

Commit

Permalink
Fix: invalid var names (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristineguadelupe authored Sep 4, 2023
1 parent 64db015 commit 0b9e4d4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/kino_explorer/data_transform_cell.ex
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ defmodule KinoExplorer.DataTransformCell do
defp to_quoted(%{"data_frame" => df, "assign_to" => variable} = attrs) do
attrs = Map.new(attrs, fn {k, v} -> convert_field(k, v) end)
missing_require = attrs.missing_require
variable = if variable && Kino.SmartCell.valid_variable_name?(variable), do: variable

nodes =
attrs.operations
Expand Down
31 changes: 31 additions & 0 deletions test/kino_explorer/data_transform_cell_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,37 @@ defmodule KinoExplorer.DataTransformCellTest do
"""
end

test "source with export to an invalid var" do
root = %{"data_frame_alias" => DF, "assign_to" => "exported_df invalid"}

operations = %{
filters: [
%{
"column" => "name",
"filter" => "equal",
"type" => "string",
"value" => "Ana",
"active" => true,
"operation_type" => "filters"
},
%{
"column" => "id",
"filter" => "less",
"type" => "integer",
"value" => "2",
"active" => true,
"operation_type" => "filters"
}
]
}

attrs = build_attrs(root, operations)

assert DataTransformCell.to_source(attrs) == """
people |> DF.to_lazy() |> DF.filter(name == "Ana" and id < 2) |> DF.collect()\
"""
end

test "source with inactive operations" do
root = %{"data_frame_alias" => DF, "assign_to" => "exported_df"}

Expand Down

0 comments on commit 0b9e4d4

Please sign in to comment.