MAINT: Move _kind_to_stem to np.core._dtype, so that it can be used as part of dtype.__repr__#12179
Conversation
numpy/core/_dtype.py
Outdated
There was a problem hiding this comment.
Goal was really just to remove this dictionary
77e2c50 to
f8c29e0
Compare
…s part of dtype.__repr__ We could consider making this a public attribute of dtype objects in future, but dtype objects have enough random attributes that I'd rather not do that.
f8c29e0 to
823431c
Compare
| except KeyError: | ||
| raise RuntimeError( | ||
| "internal dtype error, unknown kind {!r}" | ||
| .format(dtype.kind) |
There was a problem hiding this comment.
This part is not coverable without a third-party dtype that has a weird kind, which we don't have available.
There was a problem hiding this comment.
Whoa, you can separate the .format like that? Learn something every day...
There was a problem hiding this comment.
You can do whatever you like with whitespace providing its within parentheses
| base = _kind_to_stem[char] | ||
| dt = dtype(obj) | ||
| char = dt.kind | ||
| base = _kind_name(dt) |
There was a problem hiding this comment.
Failure here now raises RuntimeError rather than KeyError, which seems more useful to me.
| t = g | ||
| bits = _bits_of(t) | ||
| base = _kind_to_stem[dtype(t).kind] | ||
| base = _kind_name(dtype(t)) |
There was a problem hiding this comment.
Same remark about this now raising RuntimeError instead of KeyError for weird dtypes.
| } | ||
| if sys.version_info[0] >= 3: | ||
| _kind_to_stem.update({ | ||
| 'S': 'bytes', |
There was a problem hiding this comment.
Maybe mention the encoding? Not sure we are consistent about that though.
There was a problem hiding this comment.
As a comment, not part of the stem.
There was a problem hiding this comment.
The encoding of bytes, you mean? I think that's a property of the default U->S conversion, not of the S type itself - so the comment doesn't belong here. You can store whatever encoding you like in S (or even not text at all).
|
Thanks Eric. |
_kind_to_stem to np.core._dtype, so that it can be used as part of dtype.__repr__
We could consider making this a public attribute of dtype objects in future, but dtype objects have enough random attributes that I'd rather not do that.