summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/arrayprint.py4
-rw-r--r--numpy/core/src/multiarray/datetime_strings.c9
-rw-r--r--numpy/core/src/multiarray/datetime_strings.h2
-rw-r--r--numpy/core/tests/test_datetime.py27
-rw-r--r--numpy/core/tests/test_multiarray.py6
5 files changed, 28 insertions, 20 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
index e1df556ef..7ce6e0795 100644
--- a/numpy/core/arrayprint.py
+++ b/numpy/core/arrayprint.py
@@ -373,7 +373,7 @@ def _recursive_guard(fillvalue='...'):
@_recursive_guard()
def _array2string(a, options, separator=' ', prefix=""):
if a.size > options['threshold']:
- summary_insert = "..., "
+ summary_insert = "..."
data = _leading_trailing(a)
else:
summary_insert = ""
@@ -545,7 +545,7 @@ def _formatArray(a, format_function, rank, max_line_len,
if summary_insert and 2*edge_items < len(a):
leading_items = edge_items
trailing_items = edge_items
- summary_insert1 = summary_insert
+ summary_insert1 = summary_insert + separator
else:
leading_items = 0
trailing_items = len(a)
diff --git a/numpy/core/src/multiarray/datetime_strings.c b/numpy/core/src/multiarray/datetime_strings.c
index 716453c95..b9aeda508 100644
--- a/numpy/core/src/multiarray/datetime_strings.c
+++ b/numpy/core/src/multiarray/datetime_strings.c
@@ -885,15 +885,16 @@ lossless_unit_from_datetimestruct(npy_datetimestruct *dts)
* string was too short).
*/
NPY_NO_EXPORT int
-make_iso_8601_datetime(npy_datetimestruct *dts, char *outstr, int outlen,
+make_iso_8601_datetime(npy_datetimestruct *dts, char *outstr, npy_intp outlen,
int local, int utc, NPY_DATETIMEUNIT base, int tzoffset,
NPY_CASTING casting)
{
npy_datetimestruct dts_local;
int timezone_offset = 0;
- char *substr = outstr, sublen = outlen;
- int tmplen;
+ char *substr = outstr;
+ npy_intp sublen = outlen;
+ npy_intp tmplen;
/* Handle NaT, and treat a datetime with generic units as NaT */
if (dts->year == NPY_DATETIME_NAT || base == NPY_FR_GENERIC) {
@@ -1321,7 +1322,7 @@ add_time_zone:
string_too_short:
PyErr_Format(PyExc_RuntimeError,
"The string provided for NumPy ISO datetime formatting "
- "was too short, with length %d",
+ "was too short, with length %"NPY_INTP_FMT,
outlen);
return -1;
}
diff --git a/numpy/core/src/multiarray/datetime_strings.h b/numpy/core/src/multiarray/datetime_strings.h
index d7608565c..4e60ce929 100644
--- a/numpy/core/src/multiarray/datetime_strings.h
+++ b/numpy/core/src/multiarray/datetime_strings.h
@@ -70,7 +70,7 @@ get_datetime_iso_8601_strlen(int local, NPY_DATETIMEUNIT base);
* string was too short).
*/
NPY_NO_EXPORT int
-make_iso_8601_datetime(npy_datetimestruct *dts, char *outstr, int outlen,
+make_iso_8601_datetime(npy_datetimestruct *dts, char *outstr, npy_intp outlen,
int local, int utc, NPY_DATETIMEUNIT base, int tzoffset,
NPY_CASTING casting);
diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py
index 92a1325bc..10fa9b060 100644
--- a/numpy/core/tests/test_datetime.py
+++ b/numpy/core/tests/test_datetime.py
@@ -518,31 +518,38 @@ class TestDateTime(object):
def test_datetime_string_conversion(self):
a = ['2011-03-16', '1920-01-01', '2013-05-19']
str_a = np.array(a, dtype='S')
+ uni_a = np.array(a, dtype='U')
dt_a = np.array(a, dtype='M')
- str_b = np.empty_like(str_a)
- dt_b = np.empty_like(dt_a)
# String to datetime
assert_equal(dt_a, str_a.astype('M'))
assert_equal(dt_a.dtype, str_a.astype('M').dtype)
+ dt_b = np.empty_like(dt_a)
dt_b[...] = str_a
assert_equal(dt_a, dt_b)
+
# Datetime to string
assert_equal(str_a, dt_a.astype('S0'))
+ str_b = np.empty_like(str_a)
str_b[...] = dt_a
assert_equal(str_a, str_b)
- # Convert the 'S' to 'U'
- str_a = str_a.astype('U')
- str_b = str_b.astype('U')
-
# Unicode to datetime
- assert_equal(dt_a, str_a.astype('M'))
- assert_equal(dt_a.dtype, str_a.astype('M').dtype)
- dt_b[...] = str_a
+ assert_equal(dt_a, uni_a.astype('M'))
+ assert_equal(dt_a.dtype, uni_a.astype('M').dtype)
+ dt_b = np.empty_like(dt_a)
+ dt_b[...] = uni_a
assert_equal(dt_a, dt_b)
+
# Datetime to unicode
- assert_equal(str_a, dt_a.astype('U'))
+ assert_equal(uni_a, dt_a.astype('U'))
+ uni_b = np.empty_like(uni_a)
+ uni_b[...] = dt_a
+ assert_equal(uni_a, uni_b)
+
+ # Datetime to long string - gh-9712
+ assert_equal(str_a, dt_a.astype((np.string_, 128)))
+ str_b = np.empty(str_a.shape, dtype=(np.string_, 128))
str_b[...] = dt_a
assert_equal(str_a, str_b)
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 204285a4e..e327717b1 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -5624,7 +5624,7 @@ class TestInner(object):
class TestSummarization(object):
def test_1d(self):
A = np.arange(1001)
- strA = '[ 0 1 2 ..., 998 999 1000]'
+ strA = '[ 0 1 2 ... 998 999 1000]'
assert_(str(A) == strA)
reprA = 'array([ 0, 1, 2, ..., 998, 999, 1000])'
@@ -5632,8 +5632,8 @@ class TestSummarization(object):
def test_2d(self):
A = np.arange(1002).reshape(2, 501)
- strA = '[[ 0 1 2 ..., 498 499 500]\n' \
- ' [ 501 502 503 ..., 999 1000 1001]]'
+ strA = '[[ 0 1 2 ... 498 499 500]\n' \
+ ' [ 501 502 503 ... 999 1000 1001]]'
assert_(str(A) == strA)
reprA = 'array([[ 0, 1, 2, ..., 498, 499, 500],\n' \