From 7045cbc7e65dc13a1bb0d5ca866d455022e29f24 Mon Sep 17 00:00:00 2001 From: Mark Wiebe Date: Thu, 19 May 2011 17:09:10 -0500 Subject: ENH: Reimplement datetime dtype string parser (with error checking) The previous implementation returned the default datetime type in many cases instead of raising an exception. I also changed the hybrid C + Python implementation to be purely in C. --- numpy/core/_internal.py | 30 ------------------------------ 1 file changed, 30 deletions(-) (limited to 'numpy/core/_internal.py') diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py index 5298f412b..a5b6d117a 100644 --- a/numpy/core/_internal.py +++ b/numpy/core/_internal.py @@ -166,36 +166,6 @@ def _split(input): return newlist -format_datetime = re.compile(asbytes(r""" - (?PM8|m8|datetime64|timedelta64) - ([[] - ((?P\d+)? - (?PY|M|W|B|D|h|m|s|ms|us|ns|ps|fs|as) - (/(?P\d+))? - []]) - (//(?P\d+))?)?"""), re.X) - -# Return (baseunit, num, den, events), datetime -# from date-time string -def _datetimestring(astr): - res = format_datetime.match(astr) - if res is None: - raise ValueError("Incorrect date-time string.") - typecode = res.group('typecode') - datetime = (typecode == asbytes('M8') or typecode == asbytes('datetime64')) - defaults = [asbytes('us'), 1, 1, 1] - names = ['baseunit', 'num', 'den', 'events'] - func = [bytes, int, int, int] - dt_tuple = [] - for i, name in enumerate(names): - value = res.group(name) - if value: - dt_tuple.append(func[i](value)) - else: - dt_tuple.append(defaults[i]) - - return tuple(dt_tuple), datetime - format_re = re.compile(asbytes(r'(?P[<>|=]?)(?P *[(]?[ ,0-9]*[)]? *)(?P[<>|=]?)(?P[A-Za-z0-9.]*)')) # astr is a string (perhaps comma separated) -- cgit v1.2.1