diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2018-07-22 19:50:21 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-22 19:50:21 -0500 |
commit | 083aedba2f49e1b490d3e122f5927f0718cf202c (patch) | |
tree | 4168bd704df270ac788fcdd990be527f882685bc /numpy/core/tests | |
parent | bc021e4ae3232875fbbd13cdc74348f9893ed641 (diff) | |
parent | 9841981c3533d36582c2bd4d1fe24208de99f82f (diff) | |
download | numpy-083aedba2f49e1b490d3e122f5927f0718cf202c.tar.gz |
Merge pull request #11601 from eric-wieser/list-ctor
BUG: Make np.array([[1], 2]) and np.array([1, [2]]) behave in the same way
Diffstat (limited to 'numpy/core/tests')
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index e85a73154..3812a20d8 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -688,6 +688,9 @@ class TestScalarIndexing(object): class TestCreation(object): + """ + Test the np.array constructor + """ def test_from_attribute(self): class x(object): def __array__(self, dtype=None): @@ -903,6 +906,34 @@ class TestCreation(object): assert_raises(ValueError, np.ndarray, buffer=buf, strides=(0,), shape=(max_bytes//itemsize + 1,), dtype=dtype) + def test_jagged_ndim_object(self): + # Lists of mismatching depths are treated as object arrays + a = np.array([[1], 2, 3]) + assert_equal(a.shape, (3,)) + assert_equal(a.dtype, object) + + a = np.array([1, [2], 3]) + assert_equal(a.shape, (3,)) + assert_equal(a.dtype, object) + + a = np.array([1, 2, [3]]) + assert_equal(a.shape, (3,)) + assert_equal(a.dtype, object) + + def test_jagged_shape_object(self): + # The jagged dimension of a list is turned into an object array + a = np.array([[1, 1], [2], [3]]) + assert_equal(a.shape, (3,)) + assert_equal(a.dtype, object) + + a = np.array([[1], [2, 2], [3]]) + assert_equal(a.shape, (3,)) + assert_equal(a.dtype, object) + + a = np.array([[1], [2], [3, 3]]) + assert_equal(a.shape, (3,)) + assert_equal(a.dtype, object) + class TestStructured(object): def test_subarray_field_access(self): |