elixir-explorer / explorer

Series (one-dimensional) and dataframes (two-dimensional) for fast and elegant data exploration in Elixir
https://hexdocs.pm/explorer
MIT License
1.12k stars 123 forks source link

Print empty DataFrame #1019

Closed billylanchantin closed 3 days ago

billylanchantin commented 3 days ago

We currently raise if you try to print a DataFrame with no rows or columns:

iex(1)> df = Explorer.DataFrame.new([])
#Explorer.DataFrame<
  Polars[0 x 0]
>

iex(2)> Explorer.DataFrame.print(df)
** (ArithmeticError) bad argument in arithmetic expression
    (table_rex 4.0.0) lib/table_rex/renderer/text.ex:378: TableRex.Renderer.Text.max_dimensions/1
    (table_rex 4.0.0) lib/table_rex/renderer/text.ex:56: TableRex.Renderer.Text.render/2
    (table_rex 4.0.0) lib/table_rex/table.ex:280: TableRex.Table.render!/2
    (explorer 0.11.0-dev) lib/explorer/data_frame.ex:5976: Explorer.DataFrame.print/2
    iex:2: (file)

This PR fixes that with a default print string:

...

iex(2)> Explorer.DataFrame.print(df)
+-------------------------------------------+
| Explorer DataFrame: [rows: 0, columns: 0] |
+-------------------------------------------+

:ok

I also documented the option to the print function.

billylanchantin commented 3 days ago

This is part of fixing #1014