Skip to content

Commit 9fd99d7

Browse files
committed
Merge pull request #8832 from broessli/z-utc
Fix unrecognized 'Z' UTC designator
2 parents e5fe75e + 1e5d25a commit 9fd99d7

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

doc/source/whatsnew/v0.15.2.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ Bug Fixes
151151
- Bug in `pd.infer_freq`/`DataFrame.inferred_freq` that prevented proper sub-daily frequency inference
152152
when the index contained DST days (:issue:`8772`).
153153
- Bug where index name was still used when plotting a series with ``use_index=False`` (:issue:`8558`).
154-
155154
- Bugs when trying to stack multiple columns, when some (or all)
156155
of the level names are numbers (:issue:`8584`).
157156
- Bug in ``MultiIndex`` where ``__contains__`` returns wrong result if index is
158157
not lexically sorted or unique (:issue:`7724`)
159158
- BUG CSV: fix problem with trailing whitespace in skipped rows, (:issue:`8679`), (:issue:`8661`)
159+
- Regression in ``Timestamp`` does not parse 'Z' zone designator for UTC (:issue:`8771`)

pandas/src/datetime/np_datetime_strings.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ convert_datetimestruct_local_to_utc(pandas_datetimestruct *out_dts_utc,
363363
* to be cast to the 'unit' parameter.
364364
*
365365
* 'out' gets filled with the parsed date-time.
366-
* 'out_local' gets whether returned value contains timezone. 0 for UTC, 1 for local time.
366+
* 'out_local' gets set to 1 if the parsed time contains timezone,
367+
* to 0 otherwise.
367368
* 'out_tzoffset' gets set to timezone offset by minutes
368369
* if the parsed time was in local time,
369370
* to 0 otherwise. The values 'now' and 'today' don't get counted
@@ -785,11 +786,15 @@ parse_iso_8601_datetime(char *str, int len,
785786

786787
/* UTC specifier */
787788
if (*substr == 'Z') {
788-
/* "Z" means not local */
789+
/* "Z" should be equivalent to tz offset "+00:00" */
789790
if (out_local != NULL) {
790-
*out_local = 0;
791+
*out_local = 1;
791792
}
792793

794+
if (out_tzoffset != NULL) {
795+
*out_tzoffset = 0;
796+
}
797+
793798
if (sublen == 1) {
794799
goto finish;
795800
}

pandas/tseries/tests/test_tslib.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import datetime
77

88
from pandas.core.api import Timestamp, Series
9-
from pandas.tslib import period_asfreq, period_ordinal
9+
from pandas.tslib import period_asfreq, period_ordinal, get_timezone
1010
from pandas.tseries.index import date_range
1111
from pandas.tseries.frequencies import get_freq
1212
import pandas.tseries.offsets as offsets
@@ -298,6 +298,9 @@ def test_barely_oob_dts(self):
298298
# One us more than the maximum is an error
299299
self.assertRaises(ValueError, Timestamp, max_ts_us + one_us)
300300

301+
def test_utc_z_designator(self):
302+
self.assertEqual(get_timezone(Timestamp('2014-11-02 01:00Z').tzinfo), 'UTC')
303+
301304

302305
class TestDatetimeParsingWrappers(tm.TestCase):
303306
def test_does_not_convert_mixed_integer(self):

0 commit comments

Comments
 (0)