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

Potential improvement for DataFrame Access docs #1001

Closed mooreryan closed 4 weeks ago

mooreryan commented 1 month ago

I was thinking that it could be useful to mention what happens when trying to access a DataFrame column that does not exist.

The docs mention that DataFrame implements Access:

Explorer.DataFrame also implements the Access behaviour (also known as the brackets syntax).

When using the bracket access syntax, an error is raised rather than returning nil, as the Access docs mention:

Both return nil if the key does not exist

Here is what happens:

df =
  DataFrame.new(
    a: [1, 2, 3],
    b: [10, 20, 30]
  )

df["c"]

** (ArgumentError) could not find column name "c". The available columns are: ["a", "b"].
If you are attempting to interpolate a value, use ^c.

I was thinking an example like this in the DataFrame docs could be helpful. If this would be welcome, I could open a PR request for review.

(For more context, this is related to a question I asked on the Elixir Forum.)

josevalim commented 1 month ago

Please send a PR adding clarifications to our docs on Access, we can work on it together :)