8000 MAINT: Cleaned up mintypecode for Py3 · numpy/numpy@0b83bf9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b83bf9

Browse files
committed
MAINT: Cleaned up mintypecode for Py3
Using generators instead of full-blown lists Using set for search instead of list Using min to get single element insteaf of sorting full list
1 parent 2c14c5b commit 0b83bf9

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

numpy/lib/type_check.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,14 @@ def mintypecode(typechars, typeset='GDFgdf', default='d'):
6868
'G'
6969
7070
"""
71-
typecodes = [(isinstance(t, str) and t) or asarray(t).dtype.char
72-
for t in typechars]
73-
intersection = [t for t in typecodes if t in typeset]
71+
typecodes = ((isinstance(t, str) and t) or asarray(t).dtype.char
72+
for t in typechars)
73+
intersection = set(t for t in typecodes if t in typeset)
7474
if not intersection:
7575
return default
7676
if 'F' in intersection and 'd' in intersection:
7777
return 'D'
78-
l = [(_typecodes_by_elsize.index(t), t) for t in intersection]
79-
l.sort()
80-
return l[0][1]
78+
return min((_typecodes_by_elsize.index(t), t) for t in intersection)[1]
8179

8280

8381
def _asfarray_dispatcher(a, dtype=None):

0 commit comments

Comments
 (0)
0