Skip to content

Commit

Permalink
Handle nil in value_to_string (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendon9x authored Aug 26, 2024
1 parent 74461a9 commit f447c02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/kino/explorer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ defmodule Kino.Explorer do
end)
end

defp value_to_string(_, value) when is_nil(value), do: ""

defp value_to_string("binary", value) do
inspect_opts = Inspect.Opts.new([])
if String.printable?(value, inspect_opts.limit), do: value, else: inspect(value)
Expand Down
6 changes: 6 additions & 0 deletions test/kino/explorer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,12 @@ defmodule Kino.ExplorerTest do
} = data
end

test "correctly handles nil rendering when type is binary" do
df = Explorer.DataFrame.new([a: [nil]], dtypes: [a: :binary])
data = connect(Kino.Explorer.new(df))
assert data.content.data == [[""]]
end

test "correctly handles data frames with binary non-utf8 column values" do
df =
Explorer.DataFrame.new([x: [1, 2], y: [<<110, 120>>, <<200, 210>>]], dtypes: [y: :binary])
Expand Down

0 comments on commit f447c02

Please sign in to comment.