MCPcopy
hub / github.com/numpy/numpy / test_nested_simple

Method test_nested_simple

numpy/_core/tests/test_array_coercion.py:497–514  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

495
496class TestNested:
497 def test_nested_simple(self):
498 initial = [1.2]
499 nested = initial
500 for i in range(ncu.MAXDIMS - 1):
501 nested = [nested]
502
503 arr = np.array(nested, dtype="float64")
504 assert arr.shape == (1,) * ncu.MAXDIMS
505 with pytest.raises(ValueError):
506 np.array([nested], dtype="float64")
507
508 with pytest.raises(ValueError, match=".*would exceed the maximum"):
509 np.array([nested]) # user must ask for `object` explicitly
510
511 arr = np.array([nested], dtype=object)
512 assert arr.dtype == np.dtype("O")
513 assert arr.shape == (1,) * ncu.MAXDIMS
514 assert arr.item() is initial
515
516 def test_pathological_self_containing(self):
517 # Test that this also works for two nested sequences

Callers

nothing calls this directly

Calls 2

itemMethod · 0.80
dtypeMethod · 0.45

Tested by

no test coverage detected