Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/other/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function rename!(x::Index, nms::AbstractVector{Symbol}; makeunique::Bool=false)
if !makeunique
if length(unique(nms)) != length(nms)
dup = unique(nms[nonunique(DataFrame(nms=nms))])
dupstr = join(string.(':', dup), ", ", " and ")
dupstr = join(repr.(dup), ", ", " and ")
msg = "Duplicate variable names: $dupstr. Pass makeunique=true " *
"to make them unique using a suffix automatically."
throw(ArgumentError(msg))
Expand Down Expand Up @@ -463,7 +463,7 @@ function add_names(ind::Index, add_ind::AbstractIndex; makeunique::Bool=false)
end
if length(dups) > 0
if !makeunique
dupstr = join(string.(':', unique(u[dups])), ", ", " and ")
dupstr = join(repr.(unique(u[dups])), ", ", " and ")
msg = "Duplicate variable names: $dupstr. Pass makeunique=true " *
"to make them unique using a suffix automatically."
throw(ArgumentError(msg))
Expand Down
2 changes: 1 addition & 1 deletion src/other/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function make_unique!(names::Vector{Symbol}, src::AbstractVector{Symbol};

if length(dups) > 0
if !makeunique
dupstr = join(string.(':', unique(src[dups])), ", ", " and ")
dupstr = join(repr.(unique(src[dups])), ", ", " and ")
msg = "Duplicate variable names: $dupstr. Pass makeunique=true " *
"to make them unique using a suffix automatically."
throw(ArgumentError(msg))
Expand Down
24 changes: 24 additions & 0 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ using Test, Random, DataFrames
@test DataFrames.make_unique([:x, :x_1, :x2], makeunique=false) == [:x, :x_1, :x2]
end

@testset "duplicate-name error message uses repr for Symbols" begin
# this testset was AI generated
# Identifier-like Symbols still render as `:name`.
err = try DataFrames.make_unique([:a, :a]) catch e; e end
@test err isa ArgumentError
@test occursin(":a", err.msg)

# Symbols containing characters that aren't valid in an identifier
# must use the explicit `Symbol("...")` form so the message is
# unambiguous (previously rendered as `:column name`, which
# reads like a parse error rather than naming a single Symbol).
s = Symbol("column name")
for thunk in (
() -> DataFrames.make_unique([s, s]), # src/other/utils.jl
() -> rename!(DataFrames.Index([:a, :b]), [s, s]), # src/other/index.jl rename!
() -> hcat(DataFrame(s => 1), DataFrame(s => 2)), # src/other/index.jl add_names
)
err = try thunk() catch e; e end
@test err isa ArgumentError
@test occursin("Symbol(\"column name\")", err.msg)
@test !occursin(":column name", err.msg)
end
end

@testset "repeat count" begin
df = DataFrame(a=1:2, b=3:4)
ref = DataFrame(a=repeat(1:2, 2),
Expand Down
Loading