| 484 | |
| 485 | class 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 |