From cbded8fc37f05908a0243d36a18bddfd8e24e6cd Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Tue, 11 Sep 2018 22:16:22 -0700 Subject: MAINT: Eliminate a struct/non-struct branch in dtype.__repr__ --- numpy/core/_dtype.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'numpy/core') diff --git a/numpy/core/_dtype.py b/numpy/core/_dtype.py index 5047e194a..26c44eaaf 100644 --- a/numpy/core/_dtype.py +++ b/numpy/core/_dtype.py @@ -20,10 +20,10 @@ def __str__(dtype): def __repr__(dtype): - if dtype.fields is not None: - return _struct_repr(dtype) - else: - return "dtype({})".format(_construction_repr(dtype, include_align=True)) + arg_str = _construction_repr(dtype, include_align=False) + if dtype.isalignedstruct: + arg_str = arg_str + ", align=True" + return "dtype({})".format(arg_str) def _unpack_field(dtype, offset, title=None): @@ -292,15 +292,6 @@ def _subarray_str(dtype): ) -def _struct_repr(dtype): - s = "dtype(" - s += _struct_str(dtype, include_align=False) - if dtype.isalignedstruct: - s += ", align=True" - s += ")" - return s - - def _name_get(dtype): # provides dtype.name.__get__ -- cgit v1.2.1