Skip to content

Commit

Permalink
chore(rust): simplify slow datetime parser (#9183)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli authored Jun 3, 2023
1 parent 53ec18f commit 70eb215
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions polars/polars-io/src/csv/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,37 +423,27 @@ where
return Ok(());
};

match &buf.compiled {
Some(compiled) => match DatetimeInfer::<T::Native>::try_from(compiled.pattern) {
Ok(mut infer) => {
let parsed = infer.parse(val);
buf.compiled = Some(infer);
buf.builder.append_option(parsed);
Ok(())
}
Err(_) => {
buf.builder.append_null();
Ok(())
}
},
let pattern = match &buf.compiled {
Some(compiled) => compiled.pattern,
None => match infer_pattern_single(val) {
Some(pattern) => pattern,
None => {
buf.builder.append_null();
Ok(())
return Ok(());
}
Some(pattern) => match DatetimeInfer::<T::Native>::try_from(pattern) {
Ok(mut infer) => {
let parsed = infer.parse(val);
buf.compiled = Some(infer);
buf.builder.append_option(parsed);
Ok(())
}
Err(_) => {
buf.builder.append_null();
Ok(())
}
},
},
};
match DatetimeInfer::<T::Native>::try_from(pattern) {
Ok(mut infer) => {
let parsed = infer.parse(val);
buf.compiled = Some(infer);
buf.builder.append_option(parsed);
Ok(())
}
Err(_) => {
buf.builder.append_null();
Ok(())
}
}
}

Expand Down

0 comments on commit 70eb215

Please sign in to comment.