Skip to content

Commit

Permalink
Allow Z in native strpttime (#3382)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed May 12, 2022
1 parent 2045e1b commit fd49bc9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions polars/polars-time/src/chunkedarray/utf8/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub(super) static DATETIME_Y_M_D: &[&str] = &[
"%Y%m%d %H:%M:%S",
// 2019-04-18T02:45:55
"%Y-%m-%dT%H:%M:%S",
"%Y-%m-%dT%H:%M:%SZ",
// 2019-04-18T02:45:55.555000000
// microseconds
"%Y-%m-%dT%H:%M:%S.%6f",
Expand Down
3 changes: 3 additions & 0 deletions polars/polars-time/src/chunkedarray/utf8/strptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ pub(super) unsafe fn parse(val: &[u8], fmt: &[u8], fmt_len: u16) -> Option<Naive
nano *= 1_000_000;
break;
}
// utc can be ignored
b'Z' => {}
_ => return None,
}
}
Expand Down Expand Up @@ -122,6 +124,7 @@ pub(super) fn fmt_len(fmt: &[u8]) -> Option<u16> {
b'H' => cnt += 2,
b'M' => cnt += 2,
b'S' => cnt += 2,
b'Z' => cnt += 1,
b'9' => {
cnt += 9;
debug_assert_eq!(iter.next(), Some(&b'f'));
Expand Down
14 changes: 14 additions & 0 deletions polars/tests/it/io/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,3 +1006,17 @@ fn test_duplicate_column_err() {
let file = Cursor::new(csv);
assert!(CsvReader::new(file).finish().is_err());
}

#[test]
fn test_parse_dates_3380() -> Result<()> {
let csv = "lat;lon;validdate;t_2m:C;precip_1h:mm
46.685;7.953;2022-05-10T07:07:12Z;6.1;0.00
46.685;7.953;2022-05-10T08:07:12Z;8.8;0.00";
let file = Cursor::new(csv);
let df = CsvReader::new(file)
.with_delimiter(b';')
.with_parse_dates(true)
.finish()?;
assert_eq!(df.column("validdate")?.null_count(), 0);
Ok(())
}

0 comments on commit fd49bc9

Please sign in to comment.