Skip to content

Commit

Permalink
adding verbose error messages to make it clear what columns and data …
Browse files Browse the repository at this point in the history
…types are causing a SchemaMisMatch error when trying to concat df's using vstack and vstack_mut (#2045)
  • Loading branch information
jay-johnson committed Dec 15, 2021
1 parent d1d5661 commit 4923eb5
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions polars/polars-core/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,13 +813,30 @@ impl DataFrame {
.zip(df.columns.iter())
.try_for_each(|(left, right)| {
if left.dtype() != right.dtype() || left.name() != right.name() {
return Err(PolarsError::SchemaMisMatch(
format!(
"cannot vstack: schemas don't match of {:?} {:?}",
left, right
)
.into(),
));
if left.dtype() != right.dtype() {
return Err(PolarsError::SchemaMisMatch(
format!(
"cannot vstack: because column datatypes (dtypes) in the two DataFrames do not match for \
left.name='{}' with left.dtype={} != right.dtype={} with right.name='{}'",
left.name(),
left.dtype(),
right.dtype(),
right.name()
)
.into(),
));
}
else {
return Err(PolarsError::SchemaMisMatch(
format!(
"cannot vstack: because column names in the two DataFrames do not match for \
left.name='{}' != right.name='{}'",
left.name(),
right.name()
)
.into(),
));
}
}

left.append(right).expect("should not fail");
Expand Down

0 comments on commit 4923eb5

Please sign in to comment.