8000 MAINT: Cleaned up mintypecode for Py3 by madphysicist · Pull Request #14967 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Cleaned up mintypecode for Py3 #14967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions numpy/lib/type_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better as:
return min(intersection, key=_typecodes_by_elsize.index)



def _asfarray_dispatcher(a, dtype=None):
Expand Down
0