From 1e5d25a262e563828fa13bd7f682479cacb26c65 Mon Sep 17 00:00:00 2001 From: broessli Date: Sun, 16 Nov 2014 15:26:47 +0100 Subject: [PATCH] Fix unrecognized 'Z' UTC designator --- doc/source/whatsnew/v0.15.2.txt | 2 +- pandas/src/datetime/np_datetime_strings.c | 11 ++++++++--- pandas/tseries/tests/test_tslib.py | 5 ++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/doc/source/whatsnew/v0.15.2.txt b/doc/source/whatsnew/v0.15.2.txt index 1e84762b60caa..3aa50ad609064 100644 --- a/doc/source/whatsnew/v0.15.2.txt +++ b/doc/source/whatsnew/v0.15.2.txt @@ -151,9 +151,9 @@ 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`). - Bug where index name was still used when plotting a series with ``use_index=False`` (:issue:`8558`). - - Bugs when trying to stack multiple columns, when some (or all) of the level names are numbers (:issue:`8584`). - Bug in ``MultiIndex`` where ``__contains__`` returns wrong result if index is not lexically sorted or unique (:issue:`7724`) - BUG CSV: fix problem with trailing whitespace in skipped rows, (:issue:`8679`), (:issue:`8661`) +- Regression in ``Timestamp`` does not parse 'Z' zone designator for UTC (:issue:`8771`) diff --git a/pandas/src/datetime/np_datetime_strings.c b/pandas/src/datetime/np_datetime_strings.c index 3f09de851e231..44363fd930510 100644 --- a/pandas/src/datetime/np_datetime_strings.c +++ b/pandas/src/datetime/np_datetime_strings.c @@ -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 @@ -785,11 +786,15 @@ 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) { goto finish; } diff --git a/pandas/tseries/tests/test_tslib.py b/pandas/tseries/tests/test_tslib.py index 9adcbb4ea4a41..6c358bd99e620 100644 --- a/pandas/tseries/tests/test_tslib.py +++ b/pandas/tseries/tests/test_tslib.py @@ -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 @@ -298,6 +298,9 @@ 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') + class TestDatetimeParsingWrappers(tm.TestCase): def test_does_not_convert_mixed_integer(self):