Skip to content

Commit 2ee6d7f

Browse files
authored
Add better error message on error when pushing rows to a data frame (#3177)
1 parent e3793ce commit 2ee6d7f

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/dataframe/insertion.jl

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ function _append_or_prepend!(df1::DataFrame, df2::AbstractDataFrame; cols::Symbo
297297
deleteat!(col, 1:length(col) - nrow1)
298298
end
299299
end
300-
@error "Error adding value to column :$(_names(df1)[current_col])."
300+
@error "Error adding value to column :$(_names(df1)[current_col]). " *
301+
"Maybe it was forgotten to require column " *
302+
"element type promotion, which can be done " *
303+
"by passing the promote=true keyword argument."
301304
rethrow(err)
302305
end
303306

@@ -682,7 +685,9 @@ function _row_inserter!(df::DataFrame, loc::Integer, row::Any,
682685
end
683686
@assert length(col2) == nrows
684687
end
685-
@error "Error adding value to column :$(_names(df)[current_col])."
688+
@error "Error adding value to column :$(_names(df)[current_col]). " *
689+
"Maybe it was forgotten to ask for column element type promotion, " *
690+
"which can be done by passing the promote=true keyword argument."
686691
rethrow(err)
687692
end
688693
_drop_all_nonnote_metadata!(df)
@@ -743,7 +748,7 @@ function _dfr_row_inserter!(df::DataFrame, loc::Integer, dfr::DataFrameRow,
743748
@assert length(col2) == nrows
744749
end
745750
colname = _names(df)[col_num]
746-
throw(AssertionError("Error adding value to column :$colname"))
751+
throw(AssertionError("Error adding value to column :$colname."))
747752
end
748753
# use a function barrier to improve performance
749754
mode isa Val{:push} && pushhelper!(col, r)
@@ -828,7 +833,7 @@ function _row_inserter!(df::DataFrame, loc::Integer,
828833
end
829834
@assert length(col2) == nrows
830835
end
831-
throw(AssertionError("Error adding value to column :$colname"))
836+
throw(AssertionError("Error adding value to column :$colname."))
832837
end
833838
if haskey(row, colname)
834839
val = row[colname]
@@ -856,7 +861,10 @@ function _row_inserter!(df::DataFrame, loc::Integer,
856861
end
857862
@assert length(col2) == nrows
858863
end
859-
@error "Error adding value to column :$colname."
864+
@error "Error adding value to column :$colname. " *
865+
"Maybe it was forgotten to ask for column " *
866+
"element type promotion, which can be done " *
867+
"by passing the promote=true keyword argument."
860868
rethrow(err)
861869
end
862870
else
@@ -960,7 +968,10 @@ function _row_inserter!(df::DataFrame, loc::Integer,
960968
end
961969
@assert length(col2) == nrows
962970
end
963-
@error "Error adding value to column :$(_names(df)[current_col])."
971+
@error "Error adding value to column :$(_names(df)[current_col]). " *
972+
"Maybe it was forgotten to ask for column " *
973+
"element type promotion, which can be done " *
974+
"by passing the promote=true keyword argument."
964975
rethrow(err)
965976
end
966977
_drop_all_nonnote_metadata!(df)

0 commit comments

Comments
 (0)