@@ -84,8 +84,13 @@ function rename!(x::Index, nms::AbstractVector{Pair{Symbol, Symbol}})
8484 if ! haskey (xbackup, from)
8585 copy! (x. lookup, xbackup. lookup)
8686 x. names .= xbackup. names
87- throw (ArgumentError (" Tried renaming :$from to :$to , when :$from " *
88- " does not exist in the Index." ))
87+ if length (x) == 0
88+ throw (ArgumentError (" Tried renaming :$from to :$to , when " *
89+ " data frame has no columns." ))
90+ else
91+ throw (ArgumentError (" Tried renaming :$from to :$to , when :$from " *
92+ " does not exist in the data frame." ))
93+ end
8994 end
9095 if haskey (x, to)
9196 toholder[to] = x. lookup[to]
@@ -98,7 +103,7 @@ function rename!(x::Index, nms::AbstractVector{Pair{Symbol, Symbol}})
98103 copy! (x. lookup, xbackup. lookup)
99104 x. names .= xbackup. names
100105 throw (ArgumentError (" Tried renaming to :$(first (keys (toholder))) , " *
101- " when it already exists in the Index ." ))
106+ " when it already exists in the data frame ." ))
102107 end
103108 return x
104109end
@@ -115,7 +120,7 @@ Base.haskey(x::Index, key::Bool) =
115120 throw (ArgumentError (" invalid key: $key of type Bool" ))
116121
117122function Base. push! (x:: Index , nm:: Symbol )
118- haskey (x. lookup, nm) && throw (ArgumentError (" :$nm already exists in Index " ))
123+ haskey (x. lookup, nm) && throw (ArgumentError (" :$nm already exists in the data frame " ))
119124 x. lookup[nm] = length (x) + 1
120125 push! (x. names, nm)
121126 return x
288293 if i === nothing
289294 candidates = fuzzymatch (l, idx)
290295 if isempty (candidates)
296+ if isempty (l)
297+ throw (ArgumentError (" column name :$idx not found in the " *
298+ " data frame since it has no columns" ))
299+ end
291300 throw (ArgumentError (" column name :$idx not found in the data frame" ))
292301 end
293302 candidatesstr = join (string .(' :' , candidates), " , " , " and " )
0 commit comments