From 0b83bf91b2e4f943ba02d000f2a6fb7d51394197 Mon Sep 17 00:00:00 2001 From: "Joseph R. Fox-Rabinovitz" Date: Fri, 22 Nov 2019 21:48:57 -0500 Subject: [PATCH] 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 --- numpy/lib/type_check.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py index 586824743ae1..8b9e4b8abc58 100644 --- a/numpy/lib/type_check.py +++ b/numpy/lib/type_check.py @@ -68,16 +68,14 @@ def mintypecode(typechars, typeset='GDFgdf', default='d'): 'G' """ - typecodes = [(isinstance(t, str) and t) or asarray(t).dtype.char - for t in typechars] - intersection = [t for t in typecodes if t in typeset] + typecodes = ((isinstance(t, str) and t) or asarray(t).dtype.char + for t in typechars) + intersection = set(t for t in typecodes if t in typeset) if not intersection: return default if 'F' in intersection and 'd' in intersection: return 'D' - l = [(_typecodes_by_elsize.index(t), t) for t in intersection] - l.sort() - return l[0][1] + return min((_typecodes_by_elsize.index(t), t) for t in intersection)[1] def _asfarray_dispatcher(a, dtype=None):