Skip to content

Commit 5a25499

Browse files
committed
BUG: consider iso8601 strings as naive, not local close pandas-dev#1571
1 parent ee4a25d commit 5a25499

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

pandas/src/datetime.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,9 @@ cdef inline _string_to_dts(object val, pandas_datetimestruct* dts):
632632

633633
if PyUnicode_Check(val):
634634
val = PyUnicode_AsASCIIString(val);
635-
result = parse_iso_8601_datetime(val, len(val), PANDAS_FR_ns, NPY_UNSAFE_CASTING,
635+
636+
result = parse_iso_8601_datetime(val, len(val), PANDAS_FR_ns,
637+
NPY_UNSAFE_CASTING,
636638
dts, &islocal, &out_bestunit, &special)
637639
if result == -1:
638640
raise ValueError('Unable to parse %s' % str(val))

pandas/src/datetime/np_datetime_strings.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,16 +774,21 @@ parse_iso_8601_datetime(char *str, int len,
774774

775775
parse_timezone:
776776
if (sublen == 0) {
777+
// Unlike NumPy, treating no time zone as naive
778+
goto finish;
779+
780+
/*
777781
if (convert_datetimestruct_local_to_utc(out, out) < 0) {
778782
goto error;
779783
}
780784
781-
/* Since neither "Z" nor a time-zone was specified, it's local */
785+
// Since neither "Z" nor a time-zone was specified, it's local
782786
if (out_local != NULL) {
783787
*out_local = 1;
784788
}
785789
786790
goto finish;
791+
*/
787792
}
788793

789794
/* UTC specifier */

pandas/tseries/tests/test_timeseries.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ def test_string_na_nat_conversion(self):
575575
assert_series_equal(dresult, expected)
576576
self.assertEquals(dresult.name, 'foo')
577577

578+
def test_to_datetime_iso8601(self):
579+
result = to_datetime(["2012-01-01 00:00:00"])
580+
exp = Timestamp("2012-01-01 00:00:00")
581+
self.assert_(result[0] == exp)
582+
578583
def test_nat_vector_field_access(self):
579584
idx = DatetimeIndex(['1/1/2000', None, None, '1/4/2000'])
580585

0 commit comments

Comments
 (0)