diff options
author | Joseph Fox-Rabinovitz <madphysicist@users.noreply.github.com> | 2019-11-23 13:49:23 -0500 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2019-11-23 10:49:23 -0800 |
commit | 2fb8540ba959f02f0c2fcb2cddea192a708e6e5d (patch) | |
tree | d9284c1a83ca067e107e44766368eb949a08d7c9 /numpy/lib | |
parent | e9452bf0baece0ccee2e5bb90c322190e9b8493f (diff) | |
download | numpy-2fb8540ba959f02f0c2fcb2cddea192a708e6e5d.tar.gz |
MAINT: Cleaned up mintypecode for Py3 (#14967)
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
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/type_check.py | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py index 586824743..8b9e4b8ab 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): |