Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rust, python): improve error message when writing nested data to… #6040

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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