Skip to content

Commit

Permalink
Supported operations for lists
Browse files Browse the repository at this point in the history
  • Loading branch information
cristineguadelupe committed Jan 19, 2024
1 parent 47de2e4 commit f90f24b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
13 changes: 10 additions & 3 deletions lib/assets/data_transform_cell/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ export async function init(ctx, payload) {
operation_type="sorting"
label="Sort by"
v-model="operation.sort_by"
:options="dataFrameColumns(operation.data_options)"
:options="dataFrameColumnsByTypes(sortTypes, operation.data_options)"
:index="index"
:disabled="noDataFrame"
/>
Expand Down Expand Up @@ -720,6 +720,7 @@ export async function init(ctx, payload) {
dataFrames: payload.data_frame_variables,
dataFrameAlias: payload.data_frame_alias.slice(7),
pivotWiderTypes: payload.operation_types.pivot_wider,
sortTypes: payload.operation_types.sort,
summariseTypes: payload.operation_types.summarise,
queriedFilterTypes: payload.operation_types.queried_filter,
fillMissingOptions: payload.operation_options.fill_missing,
Expand Down Expand Up @@ -752,8 +753,14 @@ 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 = ["list"]
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
21 changes: 13 additions & 8 deletions lib/kino_explorer/data_transform_cell.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ defmodule KinoExplorer.DataTransformCell do
"string",
"time"
]
@special_column_types ["list"]
@filter_options %{
"binary" => ["equal", "contains", "not contains", "not equal"],
"boolean" => ["equal", "not equal"],
Expand All @@ -32,7 +33,8 @@ defmodule KinoExplorer.DataTransformCell do
"float" => ["less", "less equal", "equal", "not equal", "greater equal", "greater"],
"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"]
"time" => ["less", "less equal", "equal", "not equal", "greater equal", "greater"],
"list" => []
}
@fill_missing_options %{
"binary" => ["forward", "backward", "max", "min", "scalar"],
Expand All @@ -45,10 +47,11 @@ defmodule KinoExplorer.DataTransformCell do
"float" => ["forward", "backward", "max", "min", "mean", "scalar", "nan"],
"integer" => ["forward", "backward", "max", "min", "mean", "scalar"],
"string" => ["forward", "backward", "max", "min", "scalar"],
"time" => ["forward", "backward", "max", "min", "mean", "scalar"]
"time" => ["forward", "backward", "max", "min", "mean", "scalar"],
"list" => ["forward", "backward"]
}
@summarise_options %{
count: @column_types,
count: @column_types ++ @special_column_types,
max: [
"date",
"datetime[ms]",
Expand All @@ -69,16 +72,17 @@ defmodule KinoExplorer.DataTransformCell do
"integer",
"time"
],
n_distinct: @column_types,
nil_count: @column_types,
n_distinct: @column_types ++ @special_column_types,
nil_count: @column_types ++ @special_column_types,
standard_deviation: ["float", "integer"],
sum: ["boolean", "float", "integer"],
variance: ["float", "integer"]
}
@pivot_wider_types %{
names_from: @column_types,
values_from: @column_types
values_from: @column_types ++ @special_column_types
}
@sort_types @column_types
@queried_filter_options [
"mean",
"median",
Expand Down Expand Up @@ -139,7 +143,8 @@ defmodule KinoExplorer.DataTransformCell do
},
operation_types: %{
pivot_wider: @pivot_wider_types,
queried_filter: @queried_filter_types
queried_filter: @queried_filter_types,
sort: @sort_types
},
missing_require: nil
)
Expand Down Expand Up @@ -980,6 +985,6 @@ defmodule KinoExplorer.DataTransformCell do
end

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

0 comments on commit f90f24b

Please sign in to comment.