Skip to content

Commit 768d90e

Browse files
committed
BUG: raise exceptions out of trying to parse iso8601 strings
1 parent d247c62 commit 768d90e

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

pandas/src/datetime.pyx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -624,17 +624,18 @@ cdef inline int64_t _date_to_datetime64(object val,
624624
return pandas_datetimestruct_to_datetime(PANDAS_FR_ns, dts)
625625

626626

627-
cdef inline int _string_to_dts(object val, pandas_datetimestruct* dts) except -1:
627+
cdef inline _string_to_dts(object val, pandas_datetimestruct* dts):
628628
cdef:
629629
npy_bool islocal, special
630630
PANDAS_DATETIMEUNIT out_bestunit
631+
int result
631632

632633
if PyUnicode_Check(val):
633634
val = PyUnicode_AsASCIIString(val);
634-
parse_iso_8601_datetime(val, len(val), PANDAS_FR_ns, NPY_UNSAFE_CASTING,
635-
dts, &islocal, &out_bestunit, &special)
636-
return 0
637-
635+
result = parse_iso_8601_datetime(val, len(val), PANDAS_FR_ns, NPY_UNSAFE_CASTING,
636+
dts, &islocal, &out_bestunit, &special)
637+
if result == -1:
638+
raise ValueError('Unable to parse %s' % str(val))
638639

639640
def array_to_datetime(ndarray[object] values, raise_=False, dayfirst=False):
640641
cdef:

pandas/tseries/tests/test_daterange.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44

55
import numpy as np
66

7-
import pandas.core.datetools as datetools
8-
from pandas.tseries.offsets import generate_range
97
from pandas.core.index import Index
108
from pandas.tseries.index import DatetimeIndex
119

10+
from pandas import Timestamp
11+
from pandas.tseries.offsets import generate_range
1212
from pandas.tseries.index import bdate_range, date_range
1313
import pandas.tseries.tools as tools
1414

15+
import pandas.core.datetools as datetools
16+
1517
def eq_gen_range(kwargs, expected):
1618
rng = generate_range(**kwargs)
1719
assert(np.array_equal(list(rng), expected))
@@ -258,6 +260,9 @@ def test_misc(self):
258260

259261
def test_date_parse_failure(self):
260262
badly_formed_date = '2007/100/1'
263+
264+
self.assertRaises(ValueError, Timestamp, badly_formed_date)
265+
261266
self.assertRaises(ValueError, bdate_range, start=badly_formed_date,
262267
periods=10)
263268
self.assertRaises(ValueError, bdate_range, end=badly_formed_date,

test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ coverage erase
33
# nosetests pandas/tests/test_index.py --with-coverage --cover-package=pandas.core --pdb-failure --pdb
44
#nosetests -w pandas --with-coverage --cover-package=pandas --pdb-failure --pdb #--cover-inclusive
55
#nosetests -A "not slow" -w pandas/tseries --with-coverage --cover-package=pandas.tseries $* #--cover-inclusive
6-
nosetests -w pandas --with-coverage --cover-package=pandas $*
6+
nosetests -w pandas -v --with-coverage --cover-package=pandas $*
77
# nosetests -w pandas/io --with-coverage --cover-package=pandas.io --pdb-failure --pdb
88
# nosetests -w pandas/core --with-coverage --cover-package=pandas.core --pdb-failure --pdb
99
# nosetests -w pandas/stats --with-coverage --cover-package=pandas.stats

0 commit comments

Comments
 (0)