Skip to content

Commit

Permalink
Update to sort_with and sort_by (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristine Guadelupe authored Jan 7, 2024
1 parent f2ba8e6 commit 3db12f3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/kino/explorer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ defmodule Kino.Explorer do
defp order_by(df, nil), do: df

defp order_by(df, %{key: column, direction: direction}) do
DataFrame.arrange_with(df, &[{direction, &1[column]}])
DataFrame.sort_with(df, &[{direction, &1[column]}])
end

defp records_to_data(columns, records) do
Expand Down
2 changes: 1 addition & 1 deletion lib/kino_explorer/data_transform_cell.ex
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ defmodule KinoExplorer.DataTransformCell do
end
|> then(fn args -> if args != [], do: [args] end)

%{field: :sorting, name: :arrange, args: sorting_args}
%{field: :sorting, name: :sort_by, args: sorting_args}
end

defp to_quoted([%{operation_type: :summarise} | _] = summarization) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule KinoExplorer.MixProject do
defp deps do
[
{:kino, "~> 0.12.2"},
{:explorer, "~> 0.7.2 or ~> 0.8"},
{:explorer, github: "elixir-explorer/explorer"},
{:rustler, "~> 0.29.0", optional: true},
{:ex_doc, "~> 0.31.0", only: :dev, runtime: false}
]
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
%{
"aws_signature": {:hex, :aws_signature, "0.3.1", "67f369094cbd55ffa2bbd8cc713ede14b195fcfb45c86665cd7c5ad010276148", [:rebar3], [], "hexpm", "50fc4dc1d1f7c2d0a8c63f455b3c66ecd74c1cf4c915c768a636f9227704a674"},
"castore": {:hex, :castore, "1.0.4", "ff4d0fb2e6411c0479b1d965a814ea6d00e51eb2f58697446e9c41a97d940b28", [:mix], [], "hexpm", "9418c1b8144e11656f0be99943db4caf04612e3eaecefb5dae9a2a87565584f8"},
"castore": {:hex, :castore, "1.0.5", "9eeebb394cc9a0f3ae56b813459f990abb0a3dedee1be6b27fdb50301930502f", [:mix], [], "hexpm", "8d7c597c3e4a64c395980882d4bca3cebb8d74197c590dc272cfd3b6a6310578"},
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
"ex_doc": {:hex, :ex_doc, "0.31.0", "06eb1dfd787445d9cab9a45088405593dd3bb7fe99e097eaa71f37ba80c7a676", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "5350cafa6b7f77bdd107aa2199fe277acf29d739aba5aee7e865fc680c62a110"},
"explorer": {:hex, :explorer, "0.7.2", "6667bba5bc4ed3f65b08f3d2fa223011726aa1500f3ecb0bfcceede856fc7972", [:mix], [{:adbc, "~> 0.1", [hex: :adbc, repo: "hexpm", optional: true]}, {:aws_signature, "~> 0.3", [hex: :aws_signature, repo: "hexpm", optional: false]}, {:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:fss, "~> 0.1", [hex: :fss, repo: "hexpm", optional: false]}, {:nx, "~> 0.4", [hex: :nx, repo: "hexpm", optional: true]}, {:rustler, "~> 0.29.0", [hex: :rustler, repo: "hexpm", optional: true]}, {:rustler_precompiled, "~> 0.7", [hex: :rustler_precompiled, repo: "hexpm", optional: false]}, {:table, "~> 0.1.2", [hex: :table, repo: "hexpm", optional: false]}, {:table_rex, "~> 3.1.1 or ~> 4.0.0", [hex: :table_rex, repo: "hexpm", optional: false]}], "hexpm", "c1d89f1602ea336f69d9e0336cf4f68360f9e986652b0f74b7d6bacb2c978db0"},
"explorer": {:git, "https://github.com/elixir-explorer/explorer.git", "742a072cba45b3fea83ffe59dba8500205eb45d8", []},
"fss": {:hex, :fss, "0.1.1", "9db2344dbbb5d555ce442ac7c2f82dd975b605b50d169314a20f08ed21e08642", [:mix], [], "hexpm", "78ad5955c7919c3764065b21144913df7515d52e228c09427a004afe9c1a16b0"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
"kino": {:hex, :kino, "0.12.2", "3840f58891860a887a71d042be966f50a3bc2697243d031a46eab19ac101d866", [:mix], [{:fss, "~> 0.1.0", [hex: :fss, repo: "hexpm", optional: false]}, {:nx, "~> 0.1", [hex: :nx, repo: "hexpm", optional: true]}, {:table, "~> 0.1.2", [hex: :table, repo: "hexpm", optional: false]}], "hexpm", "4347a1c30b88999eaa82da6a5a651f8d79f639539f1c3189fb75ac3c03ebab4b"},
Expand Down
12 changes: 10 additions & 2 deletions test/kino/explorer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ defmodule Kino.ExplorerTest do
} = data
end

test "does not compute summary for unsupported lists" do
test "support data summary for lists" do
df = Explorer.DataFrame.new(%{list: Explorer.Series.from_list([[1, 2], [1]])})

widget = Kino.Explorer.new(df)
Expand All @@ -199,7 +199,15 @@ defmodule Kino.ExplorerTest do
assert %{
content: %{
columns: [
%{key: "0", label: "list", summary: %{keys: [], values: []}, type: "list"}
%{
key: "0",
label: "list",
summary: %{
keys: ["unique", "top", "top freq", "nulls"],
values: ["2", <<1, 2>>, "1", "0"]
},
type: "list"
}
]
}
} = data
Expand Down
20 changes: 10 additions & 10 deletions test/kino_explorer/data_transform_cell_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ defmodule KinoExplorer.DataTransformCellTest do
assert DataTransformCell.to_source(attrs) == """
people
|> Explorer.DataFrame.lazy()
|> Explorer.DataFrame.arrange(asc: name)
|> Explorer.DataFrame.sort_by(asc: name)
|> Explorer.DataFrame.collect()\
"""
end
Expand All @@ -256,7 +256,7 @@ defmodule KinoExplorer.DataTransformCellTest do
assert DataTransformCell.to_source(attrs) == """
people
|> Explorer.DataFrame.lazy()
|> Explorer.DataFrame.arrange(asc: name, desc: id)
|> Explorer.DataFrame.sort_by(asc: name, desc: id)
|> Explorer.DataFrame.collect()\
"""
end
Expand Down Expand Up @@ -686,7 +686,7 @@ defmodule KinoExplorer.DataTransformCellTest do
df
|> Explorer.DataFrame.lazy()
|> Explorer.DataFrame.filter(col("full name") == "Ana" and id < 2)
|> Explorer.DataFrame.arrange(asc: col("full name"), desc: id)
|> Explorer.DataFrame.sort_by(asc: col("full name"), desc: id)
|> Explorer.DataFrame.collect()\
"""
end
Expand Down Expand Up @@ -1164,7 +1164,7 @@ defmodule KinoExplorer.DataTransformCellTest do
people
|> DF.lazy()
|> DF.filter(name == "Ana")
|> DF.arrange(asc: col("full name"))
|> DF.sort_by(asc: col("full name"))
|> DF.collect()\
"""
end
Expand Down Expand Up @@ -1219,7 +1219,7 @@ defmodule KinoExplorer.DataTransformCellTest do
people
|> DF.lazy()
|> DF.filter(name == "Ana" and id < 2)
|> DF.arrange(asc: col("full name"))
|> DF.sort_by(asc: col("full name"))
|> DF.filter(contains(surname, "Santiago"))
|> DF.collect()\
"""
Expand Down Expand Up @@ -1320,7 +1320,7 @@ defmodule KinoExplorer.DataTransformCellTest do
people
|> Explorer.DataFrame.lazy()
|> Explorer.DataFrame.filter(col("full name") == "Ana")
|> Explorer.DataFrame.arrange(asc: col("full name"))\
|> Explorer.DataFrame.sort_by(asc: col("full name"))\
"""
end

Expand Down Expand Up @@ -1354,7 +1354,7 @@ defmodule KinoExplorer.DataTransformCellTest do
simple_data
|> Explorer.DataFrame.new(lazy: true)
|> Explorer.DataFrame.filter(col("full name") == "Ana")
|> Explorer.DataFrame.arrange(asc: col("full name"))\
|> Explorer.DataFrame.sort_by(asc: col("full name"))\
"""
end

Expand Down Expand Up @@ -1417,7 +1417,7 @@ defmodule KinoExplorer.DataTransformCellTest do
attrs = build_attrs(root, operations)

assert DataTransformCell.to_source(attrs) == """
teams |> DF.lazy() |> DF.group_by("weekdays") |> DF.collect() |> DF.arrange(asc: weekdays)\
teams |> DF.lazy() |> DF.group_by("weekdays") |> DF.collect() |> DF.sort_by(asc: weekdays)\
"""
end

Expand Down Expand Up @@ -1502,7 +1502,7 @@ defmodule KinoExplorer.DataTransformCellTest do
|> DF.lazy()
|> DF.group_by(["cement", "country", "bunker_fuels"])
|> DF.collect()
|> DF.arrange(asc: bunker_fuels)
|> DF.sort_by(asc: bunker_fuels)
|> DF.group_by("cement")\
"""
end
Expand Down Expand Up @@ -1540,7 +1540,7 @@ defmodule KinoExplorer.DataTransformCellTest do
|> DF.lazy()
|> DF.group_by(["cement", "country", "bunker_fuels"])
|> DF.collect()
|> DF.arrange(asc: bunker_fuels)
|> DF.sort_by(asc: bunker_fuels)
|> DF.group_by("cement")\
"""
end
Expand Down

0 comments on commit 3db12f3

Please sign in to comment.