summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2018-09-14 08:46:04 -0500
committerGitHub <noreply@github.com>2018-09-14 08:46:04 -0500
commit3c89e2f913406f55b6e998017c1149e3ba383bcc (patch)
treecf1460bde3ca210e7e7f9ef30005a87a251db523
parented124950726b469a1cf75835940c215dfb20c69f (diff)
parentcbded8fc37f05908a0243d36a18bddfd8e24e6cd (diff)
downloadnumpy-3c89e2f913406f55b6e998017c1149e3ba383bcc.tar.gz
Merge pull request #11949 from eric-wieser/tidy-_dtype
MAINT: Small tidy-ups to `np.core._dtype`
-rw-r--r--numpy/core/_dtype.py20
1 files changed, 7 insertions, 13 deletions
diff --git a/numpy/core/_dtype.py b/numpy/core/_dtype.py
index 7c79c6f5a..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):
@@ -73,8 +73,11 @@ def _construction_repr(dtype, include_align=False, short=False):
return _struct_str(dtype, include_align=include_align)
elif dtype.subdtype:
return _subarray_str(dtype)
+ else:
+ return _scalar_str(dtype, short=short)
+def _scalar_str(dtype, short):
byteorder = _byte_order_str(dtype)
if dtype.type == np.bool_:
@@ -289,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__