From 5d578d86ae6c9ae371cebfa0f52c0ce672ed8845 Mon Sep 17 00:00:00 2001 From: Cristine Guadelupe Date: Thu, 30 Nov 2023 21:21:35 -0300 Subject: [PATCH 1/2] Update types - Explorer 0.7.2 --- lib/kino/explorer.ex | 6 ++++-- mix.exs | 2 +- mix.lock | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/kino/explorer.ex b/lib/kino/explorer.ex index a2dccb3..c1436e2 100644 --- a/lib/kino/explorer.ex +++ b/lib/kino/explorer.ex @@ -17,6 +17,8 @@ defmodule Kino.Explorer do @type t :: Kino.JS.Live.t() + @numeric_types [{:f, 64}, :integer] + @doc """ Creates a new kino displaying a given data frame or series. """ @@ -185,14 +187,14 @@ defmodule Kino.Explorer do end defp summary_type(data) do - if Series.dtype(data) in [:float, :integer], do: :numeric, else: :categorical + if Series.dtype(data) in @numeric_types, do: :numeric, else: :categorical end defp count_unique(data) do data |> Series.distinct() |> Series.count() |> to_string() end - defp type_of(dtype, _) when dtype in [:integer, :float], do: "number" + defp type_of(dtype, _) when dtype in @numeric_types, do: "number" defp type_of(dtype, _) when dtype in [ diff --git a/mix.exs b/mix.exs index e886fa0..d31a18d 100644 --- a/mix.exs +++ b/mix.exs @@ -28,7 +28,7 @@ defmodule KinoExplorer.MixProject do defp deps do [ {:kino, "~> 0.9.4 or ~> 0.10"}, - {:explorer, "~> 0.7.1 or ~> 0.8"}, + {:explorer, "~> 0.7.2 or ~> 0.8"}, {:rustler, "~> 0.29.0", optional: true}, {:ex_doc, "~> 0.30.0", only: :dev, runtime: false} ] diff --git a/mix.lock b/mix.lock index 272e967..931757b 100644 --- a/mix.lock +++ b/mix.lock @@ -1,9 +1,9 @@ %{ "aws_signature": {:hex, :aws_signature, "0.3.1", "67f369094cbd55ffa2bbd8cc713ede14b195fcfb45c86665cd7c5ad010276148", [:rebar3], [], "hexpm", "50fc4dc1d1f7c2d0a8c63f455b3c66ecd74c1cf4c915c768a636f9227704a674"}, - "castore": {:hex, :castore, "1.0.3", "7130ba6d24c8424014194676d608cb989f62ef8039efd50ff4b3f33286d06db8", [:mix], [], "hexpm", "680ab01ef5d15b161ed6a95449fac5c6b8f60055677a8e79acf01b27baa4390b"}, + "castore": {:hex, :castore, "1.0.4", "ff4d0fb2e6411c0479b1d965a814ea6d00e51eb2f58697446e9c41a97d940b28", [:mix], [], "hexpm", "9418c1b8144e11656f0be99943db4caf04612e3eaecefb5dae9a2a87565584f8"}, "earmark_parser": {:hex, :earmark_parser, "1.4.36", "487ea8ef9bdc659f085e6e654f3c3feea1d36ac3943edf9d2ef6c98de9174c13", [:mix], [], "hexpm", "a524e395634bdcf60a616efe77fd79561bec2e930d8b82745df06ab4e844400a"}, "ex_doc": {:hex, :ex_doc, "0.30.6", "5f8b54854b240a2b55c9734c4b1d0dd7bdd41f71a095d42a70445c03cf05a281", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "bd48f2ddacf4e482c727f9293d9498e0881597eae6ddc3d9562bd7923375109f"}, - "explorer": {:hex, :explorer, "0.7.1", "4eb5606b82c7593ff7f60e314b0b80d5f50e61a0d0d9d451d2f33a533dfc04be", [: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.6", [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", "e82e6e66dfa109cece947f31999d9e692ebc1efda547d75bc699a238f943abea"}, + "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"}, "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.9.4", "8d271aff6f002a5cbef04a9dbe6280e37d1bd2e9d3cbf9229d5ab751e9f25328", [:mix], [{:nx, "~> 0.1", [hex: :nx, repo: "hexpm", optional: true]}, {:table, "~> 0.1.2", [hex: :table, repo: "hexpm", optional: false]}], "hexpm", "8714634960bead29430c454f5ee45567d6bd2c651a135c807430c8c98c96f0c0"}, @@ -12,7 +12,7 @@ "makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"}, "nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"}, "rustler": {:hex, :rustler, "0.29.1", "880f20ae3027bd7945def6cea767f5257bc926f33ff50c0d5d5a5315883c084d", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:toml, "~> 0.6", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "109497d701861bfcd26eb8f5801fe327a8eef304f56a5b63ef61151ff44ac9b6"}, - "rustler_precompiled": {:hex, :rustler_precompiled, "0.7.0", "5d0834fc06dbc76dd1034482f17b1797df0dba9b491cef8bb045fcaca94bcade", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "fdf43a6835f4e4de5bfbc4c019bfb8c46d124bd4635fefa3e20d9a2bbbec1512"}, + "rustler_precompiled": {:hex, :rustler_precompiled, "0.7.1", "ecadf02cc59a0eccbaed6c1937303a5827fbcf60010c541595e6d3747d3d0f9f", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "b9e4657b99a1483ea31502e1d58c464bedebe9028808eda45c3a429af4550c66"}, "table": {:hex, :table, "0.1.2", "87ad1125f5b70c5dea0307aa633194083eb5182ec537efc94e96af08937e14a8", [:mix], [], "hexpm", "7e99bc7efef806315c7e65640724bf165c3061cdc5d854060f74468367065029"}, "table_rex": {:hex, :table_rex, "4.0.0", "3c613a68ebdc6d4d1e731bc973c233500974ec3993c99fcdabb210407b90959b", [:mix], [], "hexpm", "c35c4d5612ca49ebb0344ea10387da4d2afe278387d4019e4d8111e815df8f55"}, "toml": {:hex, :toml, "0.7.0", "fbcd773caa937d0c7a02c301a1feea25612720ac3fa1ccb8bfd9d30d822911de", [:mix], [], "hexpm", "0690246a2478c1defd100b0c9b89b4ea280a22be9a7b313a8a058a2408a2fa70"}, From 7a83d7358a047310ec207da7d45f51c9d34e252a Mon Sep 17 00:00:00 2001 From: Cristine Guadelupe Date: Fri, 1 Dec 2023 14:16:21 -0300 Subject: [PATCH 2/2] Applying suggestions --- lib/kino/explorer.ex | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/kino/explorer.ex b/lib/kino/explorer.ex index c1436e2..98a06b8 100644 --- a/lib/kino/explorer.ex +++ b/lib/kino/explorer.ex @@ -17,8 +17,6 @@ defmodule Kino.Explorer do @type t :: Kino.JS.Live.t() - @numeric_types [{:f, 64}, :integer] - @doc """ Creates a new kino displaying a given data frame or series. """ @@ -187,15 +185,13 @@ defmodule Kino.Explorer do end defp summary_type(data) do - if Series.dtype(data) in @numeric_types, do: :numeric, else: :categorical + if numeric_type?(Series.dtype(data)), do: :numeric, else: :categorical end defp count_unique(data) do data |> Series.distinct() |> Series.count() |> to_string() end - defp type_of(dtype, _) when dtype in @numeric_types, do: "number" - defp type_of(dtype, _) when dtype in [ :date, @@ -208,10 +204,16 @@ defmodule Kino.Explorer do defp type_of(:boolean, _), do: "boolean" defp type_of(:string, [data]), do: type_of_sample(data) defp type_of(:binary, _), do: "binary" - defp type_of(_, _), do: "text" + defp type_of(dtype, _), do: if(numeric_type?(dtype), do: "number", else: "text") defp type_of_sample("http" <> _rest), do: "uri" defp type_of_sample(_), do: "text" - def lazy?(%DataFrame{data: %struct{}}), do: struct.lazy() == struct + defp numeric_type?({:s, _}), do: true + defp numeric_type?({:u, _}), do: true + defp numeric_type?({:f, _}), do: true + # For backwards compatibility + defp numeric_type?(other), do: other in [:float, :integer] + + defp lazy?(%DataFrame{data: %struct{}}), do: struct.lazy() == struct end