Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def decode(self, buf, out=None):
items = self._decoder.decode(ensure_text(buf, self._text_encoding))
dec = np.empty(items[-1], dtype=items[-2])
dec[:] = items[:-2]
if out is not None:
np.copyto(out, dec)
return out
else:
return dec
def __init__(self, labels, dtype, astype='u1'):
self.dtype = np.dtype(dtype)
if self.dtype.kind not in 'UO':
raise TypeError("only unicode ('U') and object ('O') dtypes are "
"supported")
self.labels = [ensure_text(label) for label in labels]
self.astype = np.dtype(astype)
if self.astype == object:
raise TypeError('encoding as object array not supported')