#19829 closed Bug (fixed)
Index lookup fails for NumPy arrays in templates
Reported by: | Julien Phalip | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The following will crash with a ValueError
when using a NumPy array:
{{ my_numpy_array.0 }}
This is because currently Django only handles index lookups for regular Python lists, by catching a TypeError
. See how differently regular lists and NumPy arrays behave:
>>> regular_list = [1,2,3,4] >>> regular_list['0'] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: list indices must be integers, not str >>> import numpy >>> numpy_array = numpy.array([1,2,3,4]) >>> numpy_array['0'] Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: field named 0 not found.
The attached patch fixes this issue by handling ValueError
too.
Change History (5)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|---|
Version: | 1.4 → master |
comment:3 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Pull request: https://github.com/django/django/pull/728