Skip to content

MAINT: Move _kind_to_stem to np.core._dtype, so that it can be used as part of dtype.__repr__ - #12179

Merged
charris merged 1 commit into
numpy:masterfrom
eric-wieser:numerictypes-helpers
Oct 17, 2018
Merged

charris merged 1 commit into
numpy:masterfrom
eric-wieser:numerictypes-helpers

Conversation

@eric-wieser

Copy link
Copy Markdown
Member

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.

Comment thread numpy/core/_dtype.py Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Goal was really just to remove this dictionary

…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.
Comment thread numpy/core/_dtype.py
except KeyError:
raise RuntimeError(
"internal dtype error, unknown kind {!r}"
.format(dtype.kind)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This part is not coverable without a third-party dtype that has a weird kind, which we don't have available.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Whoa, you can separate the .format like that? Learn something every day...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same remark about this now raising RuntimeError instead of KeyError for weird dtypes.

Comment thread numpy/core/_dtype.py
}
if sys.version_info[0] >= 3:
_kind_to_stem.update({
'S': 'bytes',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe mention the encoding? Not sure we are consistent about that though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As a comment, not part of the stem.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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).

@charris
charris merged commit f85c71a into numpy:master Oct 17, 2018
@charris

charris commented Oct 17, 2018

Copy link
Copy Markdown
Member

Thanks Eric.

@charris charris changed the title MAINT: Move _kind_to_stem to np.core._dtype, so that it can be used as part of dtype.__repr__ MAINT: Move _kind_to_stem to np.core._dtype, so that it can be used as part of dtype.__repr__ Nov 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants