Skip to content

Commit

Permalink
Operations for Explorer struct (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristineguadelupe authored Jan 20, 2024
1 parent 5566fd5 commit e4048e7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 57 deletions.
10 changes: 7 additions & 3 deletions lib/assets/data_transform_cell/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,9 +753,13 @@ export async function init(ctx, payload) {
return data_options ? Object.keys(data_options) : [];
},
dataFrameColumnsWithTypes(data_options) {
const dataFrameColumns = data_options
? Object.entries(data_options)
: {};
const notAllowedTypes = ["struct"];
const dataOptions = Object.fromEntries(
Object.entries(data_options).filter(
([col, type]) => !notAllowedTypes.includes(type)
)
);
const dataFrameColumns = dataOptions ? Object.entries(dataOptions) : {};
const columns = Array.from(dataFrameColumns, ([name, type]) => {
return { label: `${name} (${type})`, value: name };
});
Expand Down
9 changes: 5 additions & 4 deletions lib/kino_explorer/data_transform_cell.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule KinoExplorer.DataTransformCell do
"string",
"time"
]
@composite_column_types ["list"]
@composite_column_types ["list", "struct"]
@filter_options %{
"binary" => ["equal", "contains", "not contains", "not equal"],
"boolean" => ["equal", "not equal"],
Expand All @@ -34,7 +34,8 @@ defmodule KinoExplorer.DataTransformCell do
"integer" => ["less", "less equal", "equal", "not equal", "greater equal", "greater"],
"string" => ["equal", "contains", "not contains", "not equal"],
"time" => ["less", "less equal", "equal", "not equal", "greater equal", "greater"],
"list" => ["contains", "not contains"]
"list" => ["contains", "not contains"],
"struct" => []
}
@fill_missing_options %{
"binary" => ["forward", "backward", "max", "min", "scalar"],
Expand Down Expand Up @@ -82,7 +83,7 @@ defmodule KinoExplorer.DataTransformCell do
names_from: @column_types,
values_from: @column_types ++ @composite_column_types
}
@sort_types @column_types
@sort_types @column_types ++ ["struct"]
@queried_filter_options [
"mean",
"median",
Expand Down Expand Up @@ -1010,7 +1011,7 @@ defmodule KinoExplorer.DataTransformCell do
end

defp build_data_options(df) do
df |> DataFrame.dtypes() |> normalize_dtypes() |> Map.reject(fn {_k, v} -> v == "struct" end)
df |> DataFrame.dtypes() |> normalize_dtypes()
end

defp build_filter_for_list(column, "contains", value) do
Expand Down
50 changes: 0 additions & 50 deletions test/kino_explorer/data_transform_cell_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -150,56 +150,6 @@ defmodule KinoExplorer.DataTransformCellTest do
})
end

test "removes struct-type columns from data options" do
{kino, _source} = start_smart_cell!(DataTransformCell, %{})

df =
Explorer.DataFrame.new(
[
a: ["a", "b"],
b: [1, 2],
c: ["https://elixir-lang.org", "https://www.erlang.org"],
d: [<<110, 120>>, <<200, 210>>],
e: [[1, 2], [3, 4]],
f: [%{"a" => 42}, %{"a" => 51}]
],
dtypes: [d: :binary]
)

env = Code.env_for_eval([])
DataTransformCell.scan_binding(kino.pid, binding(), env)

data_frame_variables = %{"df" => true}

assert_broadcast_event(kino, "set_available_data", %{
"data_frame_variables" => ^data_frame_variables,
"fields" => %{
operations: [
%{
"active" => true,
"column" => nil,
"data_options" =>
%{
"a" => "string",
"b" => "integer",
"c" => "string",
"d" => "binary",
"e" => "list"
} = operation,
"datalist" => [],
"filter" => nil,
"operation_type" => "filters",
"type" => "string",
"value" => nil
}
],
root_fields: %{"assign_to" => nil, "data_frame" => "df"}
}
})

refute Map.has_key?(operation, "f")
end

describe "code generation" do
test "source for a data frame without operations" do
attrs = build_attrs(%{})
Expand Down

0 comments on commit e4048e7

Please sign in to comment.