Skip to content

Commit

Permalink
chore: refactor maybe_raise_column_duplicate
Browse files Browse the repository at this point in the history
Refactor the reduction to use a list instead of a map. This preserves the ability to name the duplicated column while simplifying the procedure.

Co-authored-by: Philip Sampaio <philip.sampaio@gmail.com>
  • Loading branch information
pcapel and Philip Sampaio authored Feb 13, 2024
1 parent ce0c9ca commit a30b1c9
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/explorer/data_frame.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3635,11 +3635,10 @@ defmodule Explorer.DataFrame do
end

defp maybe_raise_column_duplicate(pairs) when is_column_pairs(pairs) do
Enum.reduce(pairs, MapSet.new(), fn {col, _val}, seen ->
case col in seen do
true -> raise ArgumentError, "duplicate column name \"#{col}\" in rename"
false -> MapSet.put(seen, col)
end
Enum.reduce(pairs, [], fn {col, _val}, seen ->
if col in seen, do: raise(ArgumentError, "duplicate column name \"#{col}\" in rename")

[col | seen]
end)
end

Expand Down

0 comments on commit a30b1c9

Please sign in to comment.