| 495 | |
| 496 | class 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 |