summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorOrestis Floros <orestisf1993@gmail.com>2018-03-31 02:33:48 +0300
committerOrestis Floros <orestisf1993@gmail.com>2018-03-31 02:33:48 +0300
commit942f986492f2a77bbac8e8ddfbc4fa480cf1809f (patch)
tree6ca1e067f0e8663e225a8c4a3a9b2def5951324c /numpy
parent7fd2a3931021fecd00a8c3d98230c2f2bf78bb46 (diff)
downloadnumpy-942f986492f2a77bbac8e8ddfbc4fa480cf1809f.tar.gz
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.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/datetime_strings.c2
-rw-r--r--numpy/core/tests/test_datetime.py7
2 files changed, 8 insertions, 1 deletions
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,12 +1255,19 @@ 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]')),
np.array(['-1980-02-29 01:02:03Z'], np.dtype('M8[s]')))
# Time zone offset