From 46647b145c100a550336c6404c9cc1b1a1bf5b2a Mon Sep 17 00:00:00 2001 From: Cristine Guadelupe Date: Wed, 6 Sep 2023 18:52:48 +0700 Subject: [PATCH] Do not crash when there's invalid tabular data --- lib/kino_explorer/data_transform_cell.ex | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/kino_explorer/data_transform_cell.ex b/lib/kino_explorer/data_transform_cell.ex index 626c2ca..096256a 100644 --- a/lib/kino_explorer/data_transform_cell.ex +++ b/lib/kino_explorer/data_transform_cell.ex @@ -843,7 +843,7 @@ defmodule KinoExplorer.DataTransformCell do case df do nil -> nil %DataFrame{} -> DataFrame.dtypes(df) |> normalize_dtypes() - _ -> df |> DataFrame.new() |> DataFrame.dtypes() |> normalize_dtypes() + _ -> maybe_data_options(df) end [Map.put(operation, "data_options", data_options)] @@ -945,4 +945,13 @@ defmodule KinoExplorer.DataTransformCell do end) |> Enum.into(%{}) end + + defp maybe_data_options(df) do + try do + df |> DataFrame.new() |> DataFrame.dtypes() |> normalize_dtypes() + rescue + _ -> + nil + end + end end