Skip to content

Fix unrecognized 'Z' UTC designator #8786

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.15.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ Bug Fixes

- Bug in `pd.infer_freq`/`DataFrame.inferred_freq` that prevented proper sub-daily frequency inference
when the index contained DST days (:issue:`8772`).
- Regression in ``Timestamp`` does not parse 'Z' zone designator for UTC (:issue:`8771`)
11 changes: 8 additions & 3 deletions pandas/src/datetime/np_datetime_strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ convert_datetimestruct_local_to_utc(pandas_datetimestruct *out_dts_utc,
* to be cast to the 'unit' parameter.
*
* 'out' gets filled with the parsed date-time.
* 'out_local' gets whether returned value contains timezone. 0 for UTC, 1 for local time.
* 'out_local' gets set to 1 if the parsed time contains timezone,
* to 0 otherwise.
* 'out_tzoffset' gets set to timezone offset by minutes
* if the parsed time was in local time,
* to 0 otherwise. The values 'now' and 'today' don't get counted
Expand Down Expand Up @@ -785,9 +786,13 @@ parse_iso_8601_datetime(char *str, int len,

/* UTC specifier */
if (*substr == 'Z') {
/* "Z" means not local */
/* "Z" should be equivalent to tz offset "+00:00" */
if (out_local != NULL) {
*out_local = 0;
*out_local = 1;
}

if (out_tzoffset != NULL) {
*out_tzoffset = 0;
}

if (sublen == 1) {
Expand Down
7 changes: 6 additions & 1 deletion pandas/tseries/tests/test_tslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import datetime

from pandas.core.api import Timestamp, Series
from pandas.tslib import period_asfreq, period_ordinal
from pandas.tslib import period_asfreq, period_ordinal, get_timezone
from pandas.tseries.index import date_range
from pandas.tseries.frequencies import get_freq
import pandas.tseries.offsets as offsets
Expand Down Expand Up @@ -298,6 +298,11 @@ def test_barely_oob_dts(self):
# One us more than the maximum is an error
self.assertRaises(ValueError, Timestamp, max_ts_us + one_us)

def test_utc_z_designator(self):
self.assertEqual(get_timezone(Timestamp('2014-11-02 01:00Z').tzinfo), 'UTC')
self.assertEqual(get_timezone(Timestamp('2014-11-02 01:00Z00').tzinfo), 'UTC')
self.assertRaises(ValueError, Timestamp, '2014-11-02 01:00Z0')


class TestDatetimeParsingWrappers(tm.TestCase):
def test_does_not_convert_mixed_integer(self):
Expand Down