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

Method test_object_subclass

numpy/core/tests/test_arrayprint.py:41–59  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

39
40 @pytest.mark.xfail(reason="See gh-10544")
41 def test_object_subclass(self):
42 class sub(np.ndarray):
43 def __new__(cls, inp):
44 obj = np.asarray(inp).view(cls)
45 return obj
46
47 def __getitem__(self, ind):
48 ret = super().__getitem__(ind)
49 return sub(ret)
50
51 # test that object + subclass is OK:
52 x = sub([None, None])
53 assert_equal(repr(x), 'sub([None, None], dtype=object)')
54 assert_equal(str(x), '[None None]')
55
56 x = sub([None, sub([None, None])])
57 assert_equal(repr(x),
58 'sub([None, sub([None, None], dtype=object)], dtype=object)')
59 assert_equal(str(x), '[None sub([None, None], dtype=object)]')
60
61 def test_0d_object_subclass(self):
62 # make sure that subclasses which return 0ds instead

Callers

nothing calls this directly

Calls 2

assert_equalFunction · 0.90
subClass · 0.70

Tested by

no test coverage detected