Skip to content

Commit

Permalink
fix: Parse 00:00 time zone as UTC (#13034)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Dec 13, 2023
1 parent 64bd345 commit 5b90db4
Show file tree
Hide file tree
Showing 2 changed files with 17 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
9 changes: 9 additions & 0 deletions py-polars/tests/unit/interop/test_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,3 +1179,12 @@ 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_valid_time_zone_13032() -> None:
arr = pa.array(
[datetime(2021, 1, 1, 0, 0, 0, 0)], type=pa.timestamp("ns", tz="00:00")
)
result = cast(pl.Series, pl.from_arrow(arr))
expected = pl.Series([datetime(2021, 1, 1)], dtype=pl.Datetime("ns", "UTC"))
assert_series_equal(result, expected)

0 comments on commit 5b90db4

Please sign in to comment.