Skip to content

Commit

Permalink
fix: parse 00:00 in dtype as UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Dec 13, 2023
1 parent 64bd345 commit dcb1be8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 8 additions & 7 deletions crates/polars-core/src/series/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,14 @@ impl Series {
#[cfg(feature = "dtype-datetime")]
ArrowDataType::Timestamp(tu, tz) => {
let mut tz = tz.clone();
if tz.as_deref() == Some("") {
tz = None;
} else if tz.as_deref() == Some("+00:00") {
tz = Some("UTC".to_string());
} else if let Some(_tz) = &tz {
#[cfg(feature = "timezones")]
validate_time_zone(_tz)?;
match tz.as_deref() {
Some("") => tz = None,
Some("+00:00") | Some("00:00") => tz = Some("UTC".to_string()),
Some(_tz) => {
#[cfg(feature = "timezones")]
validate_time_zone(_tz)?;
},
None => (),
}
let chunks = cast_chunks(&chunks, &DataType::Int64, false).unwrap();
let s = Int64Chunked::from_chunks(name, chunks)
Expand Down
6 changes: 6 additions & 0 deletions py-polars/tests/unit/interop/test_interop.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from datetime import date, datetime, time
from pathlib import Path
from typing import Any, cast

import numpy as np
Expand Down Expand Up @@ -1179,3 +1180,8 @@ def test_from_arrow_invalid_time_zone() -> None:
)
with pytest.raises(ComputeError, match=r"unable to parse time zone: '\+01:00'"):
pl.from_arrow(arr)


def test_from_avro_invalid_time_zone_13032() -> None:
result = pl.read_avro(Path("tests") / "unit/io/files/out.avro.txt")
assert result.schema["reg_id_first_swipe_at"] == pl.Datetime("us", "UTC")

0 comments on commit dcb1be8

Please sign in to comment.