MCPcopy Create free account
hub / github.com/numpy/numpy / test_nested_simple

Method test_nested_simple

numpy/core/tests/test_array_coercion.py:486–503  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

484
485class TestNested:
486 def test_nested_simple(self):
487 initial = [1.2]
488 nested = initial
489 for i in range(np.MAXDIMS - 1):
490 nested = [nested]
491
492 arr = np.array(nested, dtype="float64")
493 assert arr.shape == (1,) * np.MAXDIMS
494 with pytest.raises(ValueError):
495 np.array([nested], dtype="float64")
496
497 with pytest.raises(ValueError, match=".*would exceed the maximum"):
498 np.array([nested]) # user must ask for `object` explicitly
499
500 arr = np.array([nested], dtype=object)
501 assert arr.dtype == np.dtype("O")
502 assert arr.shape == (1,) * np.MAXDIMS
503 assert arr.item() is initial
504
505 def test_pathological_self_containing(self):
506 # 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