Skip to content

Commit

Permalink
feat(rust, python): improve error message when writing nested data to… (
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jan 4, 2023
1 parent 977c552 commit e2a407d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions polars/polars-io/src/csv/write_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::io::Write;
use arrow::temporal_conversions;
use lexical_core::{FormattedSize, ToLexical};
use memchr::{memchr, memchr2};
use polars_core::error::PolarsError::ComputeError;
use polars_core::prelude::*;
use polars_core::series::SeriesIter;
use polars_core::POOL;
Expand Down Expand Up @@ -167,6 +168,18 @@ pub(crate) fn write<W: Write>(
chunk_size: usize,
options: &mut SerializeOptions,
) -> PolarsResult<()> {
for s in df.get_columns() {
let nested = match s.dtype() {
DataType::List(_) => true,
#[cfg(feature = "dtype-struct")]
DataType::Struct(_) => true,
_ => false,
};
if nested {
return Err(ComputeError(format!("CSV format does not support nested data. Consider using a different data format. Got: '{}'", s.dtype()).into()));
}
}

// check that the double quote is valid utf8
std::str::from_utf8(&[options.quote, options.quote])
.map_err(|_| PolarsError::ComputeError("quote char leads invalid utf8".into()))?;
Expand Down

0 comments on commit e2a407d

Please sign in to comment.