From 942f986492f2a77bbac8e8ddfbc4fa480cf1809f Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Sat, 31 Mar 2018 02:33:48 +0300 Subject: ENH: datetime64: support AC dates starting with '+' Numpy allows negatives signs but throws a value error when parsing datetime strings starting with '+': >>> np.datetime64('+1000-01-01T00:00:00Z') ValueError: Error parsing datetime string "+1000-01-01T00:00:00Z" at position 0 Since the default is positive years, we just need to skip the '+' character. Fixes #10810. --- numpy/core/src/multiarray/datetime_strings.c | 2 +- numpy/core/tests/test_datetime.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'numpy') diff --git a/numpy/core/src/multiarray/datetime_strings.c b/numpy/core/src/multiarray/datetime_strings.c index 96cb66b95..4f9d8fa41 100644 --- a/numpy/core/src/multiarray/datetime_strings.c +++ b/numpy/core/src/multiarray/datetime_strings.c @@ -374,7 +374,7 @@ parse_iso_8601_datetime(char *str, Py_ssize_t len, } /* Leading '-' sign for negative year */ - if (*substr == '-') { + if (*substr == '-' || *substr == '+') { ++substr; --sublen; } diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py index 638994aee..ba291737a 100644 --- a/numpy/core/tests/test_datetime.py +++ b/numpy/core/tests/test_datetime.py @@ -1255,10 +1255,17 @@ class TestDateTime(object): # Allow space instead of 'T' between date and time assert_equal(np.array(['1980-02-29T01:02:03'], np.dtype('M8[s]')), np.array(['1980-02-29 01:02:03'], np.dtype('M8[s]'))) + # Allow positive years + assert_equal(np.array(['+1980-02-29T01:02:03'], np.dtype('M8[s]')), + np.array(['+1980-02-29 01:02:03'], np.dtype('M8[s]'))) # Allow negative years assert_equal(np.array(['-1980-02-29T01:02:03'], np.dtype('M8[s]')), np.array(['-1980-02-29 01:02:03'], np.dtype('M8[s]'))) # UTC specifier + with assert_warns(DeprecationWarning): + assert_equal( + np.array(['+1980-02-29T01:02:03'], np.dtype('M8[s]')), + np.array(['+1980-02-29 01:02:03Z'], np.dtype('M8[s]'))) with assert_warns(DeprecationWarning): assert_equal( np.array(['-1980-02-29T01:02:03'], np.dtype('M8[s]')), -- cgit v1.2.1