Skip to content

Commit

Permalink
Merge pull request numba#6489 from stuartarchibald/wip/fix_buffer_dty…
Browse files Browse the repository at this point in the history
…pe_buffer_error_message

Improve the error message for unsupported Buffer in Buffer situation.
  • Loading branch information
sklam authored Nov 17, 2020
2 parents 4b7e45d + d68d688 commit eb20ebe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion numba/core/types/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def __init__(self, dtype, ndim, layout, readonly=False, name=None):
from .misc import unliteral

if isinstance(dtype, Buffer):
raise TypeError("Buffer dtype cannot be buffer, have dtype: {}".format(dtype))
msg = ("The dtype of a Buffer type cannot itself be a Buffer type, "
"this is unsupported behaviour."
"\nThe dtype requested for the unsupported Buffer was: {}.")
raise TypeError(msg.format(dtype))
if layout not in self.LAYOUTS:
raise ValueError("Invalid layout '%s'" % layout)
self.dtype = unliteral(dtype)
Expand Down
19 changes: 19 additions & 0 deletions numba/tests/test_record_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,5 +1303,24 @@ def foo(rec, flag=None):
self.assertEqual(foo(self.ab_rec1, flag=1), self.ab_rec1[0] + k + 20)


class TestRecordArrayExceptions(TestCase):

def test_nested_array_in_buffer_raises(self):
# see issue #6473
@njit()
def foo(x):
x["y"][0] = 1

dt = np.dtype([("y", (np.uint64, 5)),])
x = np.ones(1, dtype=dt)
with self.assertRaises(TypingError) as e:
foo(x)
ex1 = "The dtype of a Buffer type cannot itself be a Buffer type"
ex2 = "unsupported Buffer was: nestedarray(uint64, (5,))"
excstr = str(e.exception)
self.assertIn(ex1, excstr)
self.assertIn(ex2, excstr)


if __name__ == '__main__':
unittest.main()

0 comments on commit eb20ebe

Please sign in to comment.