Skip to content

Commit

Permalink
BUG: raise exceptions out of trying to parse iso8601 strings
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Jun 28, 2012
1 parent d247c62 commit 768d90e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
11 changes: 6 additions & 5 deletions pandas/src/datetime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -624,17 +624,18 @@ cdef inline int64_t _date_to_datetime64(object val,
return pandas_datetimestruct_to_datetime(PANDAS_FR_ns, dts)


cdef inline int _string_to_dts(object val, pandas_datetimestruct* dts) except -1:
cdef inline _string_to_dts(object val, pandas_datetimestruct* dts):
cdef:
npy_bool islocal, special
PANDAS_DATETIMEUNIT out_bestunit
int result

if PyUnicode_Check(val):
val = PyUnicode_AsASCIIString(val);
parse_iso_8601_datetime(val, len(val), PANDAS_FR_ns, NPY_UNSAFE_CASTING,
dts, &islocal, &out_bestunit, &special)
return 0

result = parse_iso_8601_datetime(val, len(val), PANDAS_FR_ns, NPY_UNSAFE_CASTING,
dts, &islocal, &out_bestunit, &special)
if result == -1:
raise ValueError('Unable to parse %s' % str(val))

def array_to_datetime(ndarray[object] values, raise_=False, dayfirst=False):
cdef:
Expand Down
9 changes: 7 additions & 2 deletions pandas/tseries/tests/test_daterange.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

import numpy as np

import pandas.core.datetools as datetools
from pandas.tseries.offsets import generate_range
from pandas.core.index import Index
from pandas.tseries.index import DatetimeIndex

from pandas import Timestamp
from pandas.tseries.offsets import generate_range
from pandas.tseries.index import bdate_range, date_range
import pandas.tseries.tools as tools

import pandas.core.datetools as datetools

def eq_gen_range(kwargs, expected):
rng = generate_range(**kwargs)
assert(np.array_equal(list(rng), expected))
Expand Down Expand Up @@ -258,6 +260,9 @@ def test_misc(self):

def test_date_parse_failure(self):
badly_formed_date = '2007/100/1'

self.assertRaises(ValueError, Timestamp, badly_formed_date)

self.assertRaises(ValueError, bdate_range, start=badly_formed_date,
periods=10)
self.assertRaises(ValueError, bdate_range, end=badly_formed_date,
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ coverage erase
# nosetests pandas/tests/test_index.py --with-coverage --cover-package=pandas.core --pdb-failure --pdb
#nosetests -w pandas --with-coverage --cover-package=pandas --pdb-failure --pdb #--cover-inclusive
#nosetests -A "not slow" -w pandas/tseries --with-coverage --cover-package=pandas.tseries $* #--cover-inclusive
nosetests -w pandas --with-coverage --cover-package=pandas $*
nosetests -w pandas -v --with-coverage --cover-package=pandas $*
# nosetests -w pandas/io --with-coverage --cover-package=pandas.io --pdb-failure --pdb
# nosetests -w pandas/core --with-coverage --cover-package=pandas.core --pdb-failure --pdb
# nosetests -w pandas/stats --with-coverage --cover-package=pandas.stats
Expand Down

0 comments on commit 768d90e

Please sign in to comment.