Skip to content

Commit

Permalink
Add access example to DataFrame docs (#1001) (#1004)
Browse files Browse the repository at this point in the history
  • Loading branch information
mooreryan authored Oct 24, 2024
1 parent 11f66a4 commit 6e40319
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/explorer/data_frame.ex
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ defmodule Explorer.DataFrame do
iex> df["class"][3]
1
When trying to access a column in the dataframe that does not exist, an `ArgumentError` is raised.
iex> df = Explorer.DataFrame.new(a: [1, 2, 3])
iex> df["b"]
** (ArgumentError) could not find column name "b". The available columns are: ["a"].
If you are attempting to interpolate a value, use ^b.
"""

alias __MODULE__, as: DataFrame
Expand Down
2 changes: 1 addition & 1 deletion lib/explorer/shared.ex
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ defmodule Explorer.Shared do
List.to_string(
[
"could not find column name \"#{name}\"" | did_you_mean(name, df.names)
] ++ ["\nIf you are attempting to interpolate a value, use ^#{name}.\n"]
] ++ ["\nIf you are attempting to interpolate a value, use ^#{name}."]
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/explorer/series_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3471,7 +3471,7 @@ defmodule Explorer.SeriesTest do
s = Series.from_list([1, 2, 3, 4])

message =
"could not find column name \"n\". The available columns are: [\"_\"].\nIf you are attempting to interpolate a value, use ^n.\n"
"could not find column name \"n\". The available columns are: [\"_\"].\nIf you are attempting to interpolate a value, use ^n."

assert_raise ArgumentError, message, fn ->
Series.filter(s, n > 2)
Expand Down Expand Up @@ -3521,7 +3521,7 @@ defmodule Explorer.SeriesTest do
s = Series.from_list([1, 2, 3, 4])

message =
"could not find column name \"n\". The available columns are: [\"_\"].\nIf you are attempting to interpolate a value, use ^n.\n"
"could not find column name \"n\". The available columns are: [\"_\"].\nIf you are attempting to interpolate a value, use ^n."

assert_raise ArgumentError, message, fn ->
Series.map(s, n * 2)
Expand Down

0 comments on commit 6e40319

Please sign in to comment.