Skip to content

Commit c03e92f

Browse files
committed
Merge branch 'fix-z-designator' of https://github.com/broessli/pandas into broessli-fix-z-designator
Conflicts: doc/source/whatsnew/v0.15.2.txt
2 parents e9cef99 + 0e02d5f commit c03e92f

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

doc/source/whatsnew/v0.15.2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,4 @@ Bug Fixes
9393

9494
- Bug in `pd.infer_freq`/`DataFrame.inferred_freq` that prevented proper sub-daily frequency inference
9595
when the index contained DST days (:issue:`8772`).
96+
- 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,9 +786,13 @@ 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;
792+
}
793+
794+
if (out_tzoffset != NULL) {
795+
*out_tzoffset = 0;
791796
}
792797

793798
if (sublen == 1) {

pandas/tseries/tests/test_tslib.py

+6-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,11 @@ 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+
self.assertEqual(get_timezone(Timestamp('2014-11-02 01:00Z00').tzinfo), 'UTC')
304+
self.assertRaises(ValueError, Timestamp, '2014-11-02 01:00Z0')
305+
301306

302307
class TestDatetimeParsingWrappers(tm.TestCase):
303308
def test_does_not_convert_mixed_integer(self):

0 commit comments

Comments
 (0)