ENH: store the 'codes' for a labelarray in the narrowest int type possible

This commit is contained in:
Joe Jevnik
2017-02-02 20:58:36 -05:00
parent d9321f4795
commit d378c9fca3
4 changed files with 236 additions and 80 deletions
+16
View File
@@ -69,6 +69,13 @@ INT_DTYPES_BY_SIZE_BYTES = OrderedDict([
(8, dtype('int64')),
])
UNSIGNED_INT_DTYPES_BY_SIZE_BYTES = OrderedDict([
(1, dtype('uint8')),
(2, dtype('uint16')),
(4, dtype('uint32')),
(8, dtype('uint64')),
])
def int_dtype_with_size_in_bytes(size):
try:
@@ -77,6 +84,15 @@ def int_dtype_with_size_in_bytes(size):
raise ValueError("No integral dtype whose size is %d bytes." % size)
def unsigned_int_dtype_with_size_in_bytes(size):
try:
return UNSIGNED_INT_DTYPES_BY_SIZE_BYTES[size]
except KeyError:
raise ValueError(
"No unsigned integral dtype whose size is %d bytes." % size
)
class NoDefaultMissingValue(Exception):
pass