Skip to content

Commit

Permalink
check schema in vstack
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Nov 18, 2021
1 parent 83f1d6f commit 86ac5e0
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion polars/polars-core/src/chunked_array/list/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl ListChunked {
let length = self.len();
for s in other {
if s.dtype() != dtype {
return Err(PolarsError::DataTypeMisMatch(
return Err(PolarsError::SchemaMisMatch(
format!("cannot concat {:?} into a list of {:?}", s.dtype(), dtype).into(),
));
}
Expand Down
4 changes: 2 additions & 2 deletions polars/polars-core/src/chunked_array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl<T> ChunkedArray<T> {
// dtype will be correct.
Ok(unsafe { self.unpack_series_matching_physical_type(series) })
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack series {:?} into matching type {:?}",
series,
Expand Down Expand Up @@ -318,7 +318,7 @@ impl<T> ChunkedArray<T> {
self.chunks.push(other);
Ok(())
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot append array of type {:?} in array of type {:?}",
other.data_type(),
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/chunked_array/object/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ where
#[inline]
pub fn append_value_from_any(&mut self, v: &dyn Any) -> Result<()> {
match v.downcast_ref::<T>() {
None => Err(PolarsError::DataTypeMisMatch(
None => Err(PolarsError::SchemaMisMatch(
"cannot downcast any in ObjectBuilder".into(),
)),
Some(v) => {
Expand Down
4 changes: 2 additions & 2 deletions polars/polars-core/src/chunked_array/ops/is_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl IsIn for Utf8Chunked {
ca.rename(self.name());
Ok(ca)
}
_ => Err(PolarsError::DataTypeMisMatch(
_ => Err(PolarsError::SchemaMisMatch(
format!(
"cannot do is_in operation with left a dtype: {:?} and right a dtype {:?}",
self.dtype(),
Expand Down Expand Up @@ -163,7 +163,7 @@ impl IsIn for BooleanChunked {
.collect_trusted();
Ok(ca)
}
_ => Err(PolarsError::DataTypeMisMatch(
_ => Err(PolarsError::SchemaMisMatch(
format!(
"cannot do is_in operation with left a dtype: {:?} and right a dtype {:?}",
self.dtype(),
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum PolarsError {
#[error("Invalid operation {0}")]
InvalidOperation(ErrString),
#[error("Data types don't match: {0}")]
DataTypeMisMatch(ErrString),
SchemaMisMatch(ErrString),
#[error("Not found: {0}")]
NotFound(String),
#[error("Lengths don't match: {0}")]
Expand Down
8 changes: 4 additions & 4 deletions polars/polars-core/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,10 @@ impl DataFrame {
.iter_mut()
.zip(df.columns.iter())
.try_for_each(|(left, right)| {
if left.dtype() != right.dtype() {
return Err(PolarsError::DataTypeMisMatch(
if left.dtype() != right.dtype() || left.name() != right.name() {
return Err(PolarsError::SchemaMisMatch(
format!(
"cannot vstack: data types don't match of {:?} {:?}",
"cannot vstack: schemas don't match of {:?} {:?}",
left, right
)
.into(),
Expand Down Expand Up @@ -2410,7 +2410,7 @@ impl std::convert::TryFrom<Vec<RecordBatch>> for DataFrame {
let schema = first_batch.schema();
for batch in batch_iter {
if batch.schema() != schema {
return Err(PolarsError::DataTypeMisMatch(
return Err(PolarsError::SchemaMisMatch(
"All record batches must have the same schema".into(),
));
}
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/series/implementations/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl SeriesTrait for SeriesWrap<BooleanChunked> {
self.0.append(other.as_ref().as_ref());
Ok(())
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
"cannot append Series; data types don't match".into(),
))
}
Expand Down
4 changes: 2 additions & 2 deletions polars/polars-core/src/series/implementations/categorical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl SeriesTrait for SeriesWrap<CategoricalChunked> {
if matches!(self.0.dtype(), DataType::Categorical) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const CategoricalChunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into categorical",
self.name(),
Expand All @@ -200,7 +200,7 @@ impl SeriesTrait for SeriesWrap<CategoricalChunked> {
self.0.append(other.as_ref().as_ref());
Ok(())
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
"cannot append Series; data types don't match".into(),
))
}
Expand Down
8 changes: 4 additions & 4 deletions polars/polars-core/src/series/implementations/dates_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ macro_rules! impl_dyn_series {
if matches!(self.0.dtype(), DataType::Time) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const TimeChunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into Time",
self.name(),
Expand All @@ -309,7 +309,7 @@ macro_rules! impl_dyn_series {
if matches!(self.0.dtype(), DataType::Date) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const DateChunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into Date",
self.name(),
Expand All @@ -324,7 +324,7 @@ macro_rules! impl_dyn_series {
if matches!(self.0.dtype(), DataType::Datetime) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const DatetimeChunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into datetime",
self.name(),
Expand Down Expand Up @@ -357,7 +357,7 @@ macro_rules! impl_dyn_series {
self.0.append(other.as_ref().as_ref());
Ok(())
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
"cannot append Series; data types don't match".into(),
))
}
Expand Down
6 changes: 3 additions & 3 deletions polars/polars-core/src/series/implementations/floats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ macro_rules! impl_dyn_series {
if matches!(self.0.dtype(), DataType::Float32) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const Float32Chunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into f32",
self.name(),
Expand All @@ -328,7 +328,7 @@ macro_rules! impl_dyn_series {
if matches!(self.0.dtype(), DataType::Float64) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const Float64Chunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into f64",
self.name(),
Expand All @@ -353,7 +353,7 @@ macro_rules! impl_dyn_series {
self.0.append(other.as_ref().as_ref());
Ok(())
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
"cannot append Series; data types don't match".into(),
))
}
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/series/implementations/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl SeriesTrait for SeriesWrap<ListChunked> {
self.0.append(other.as_ref().as_ref());
Ok(())
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
"cannot append Series; data types don't match".into(),
))
}
Expand Down
22 changes: 11 additions & 11 deletions polars/polars-core/src/series/implementations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ macro_rules! impl_dyn_series {
if matches!(self.0.dtype(), DataType::Int8) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const Int8Chunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into i8",
self.name(),
Expand All @@ -369,7 +369,7 @@ macro_rules! impl_dyn_series {
if matches!(self.0.dtype(), DataType::Int16) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const Int16Chunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into i16",
self.name(),
Expand All @@ -384,7 +384,7 @@ macro_rules! impl_dyn_series {
if matches!(self.0.dtype(), DataType::Int32) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const Int32Chunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into i32",
self.name(),
Expand All @@ -399,7 +399,7 @@ macro_rules! impl_dyn_series {
if matches!(self.0.dtype(), DataType::Int64) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const Int64Chunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into i64",
self.name(),
Expand All @@ -414,7 +414,7 @@ macro_rules! impl_dyn_series {
if matches!(self.0.dtype(), DataType::Float32) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const Float32Chunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into f32",
self.name(),
Expand All @@ -429,7 +429,7 @@ macro_rules! impl_dyn_series {
if matches!(self.0.dtype(), DataType::Float64) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const Float64Chunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into f64",
self.name(),
Expand All @@ -444,7 +444,7 @@ macro_rules! impl_dyn_series {
if matches!(self.0.dtype(), DataType::UInt8) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const UInt8Chunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into u8",
self.name(),
Expand All @@ -459,7 +459,7 @@ macro_rules! impl_dyn_series {
if matches!(self.0.dtype(), DataType::UInt16) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const UInt16Chunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into u16",
self.name(),
Expand All @@ -474,7 +474,7 @@ macro_rules! impl_dyn_series {
if matches!(self.0.dtype(), DataType::UInt32) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const UInt32Chunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into u32",
self.name(),
Expand All @@ -489,7 +489,7 @@ macro_rules! impl_dyn_series {
if matches!(self.0.dtype(), DataType::UInt64) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const UInt64Chunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into u64",
self.name(),
Expand All @@ -514,7 +514,7 @@ macro_rules! impl_dyn_series {
self.0.append(other.as_ref().as_ref());
Ok(())
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
"cannot append Series; data types don't match".into(),
))
}
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/series/implementations/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ where
ObjectChunked::append(&mut self.0, other.as_ref().as_ref());
Ok(())
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
"cannot append Series; data types don't match".into(),
))
}
Expand Down
4 changes: 2 additions & 2 deletions polars/polars-core/src/series/implementations/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl SeriesTrait for SeriesWrap<Utf8Chunked> {
if matches!(self.0.dtype(), DataType::Utf8) {
unsafe { Ok(&*(self as *const dyn SeriesTrait as *const Utf8Chunked)) }
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!(
"cannot unpack Series: {:?} of type {:?} into utf8",
self.name(),
Expand All @@ -208,7 +208,7 @@ impl SeriesTrait for SeriesWrap<Utf8Chunked> {
self.0.append(other.as_ref().as_ref());
Ok(())
} else {
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
"cannot append Series; data types don't match".into(),
))
}
Expand Down
4 changes: 2 additions & 2 deletions polars/polars-core/src/series/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ impl Series {
.into_series();
return Ok(s);
}
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!("{:?} is not a floating point datatype", self.dtype()).into(),
))
}
Expand All @@ -462,7 +462,7 @@ impl Series {
let s = ca.apply(|val| val.floor()).into_series();
return Ok(s);
}
Err(PolarsError::DataTypeMisMatch(
Err(PolarsError::SchemaMisMatch(
format!("{:?} is not a floating point datatype", self.dtype()).into(),
))
}
Expand Down

0 comments on commit 86ac5e0

Please sign in to comment.