def test_ensure_text(): bufs = [ b'adsdasdas', u'adsdasdas', np.asarray(memoryview(b'adsdasdas')), array.array('B', b'qwertyuiqwertyui') ] for buf in bufs: b = ensure_text(buf) assert isinstance(b, text_type)
def __init__(self, labels, dtype, astype='u1'): self.dtype = np.dtype(dtype) if self.dtype.kind == 'S': self.labels = [ensure_bytes(l) for l in labels] elif self.dtype.kind == 'U': self.labels = [ensure_text(l) for l in labels] else: self.labels = labels self.astype = np.dtype(astype)
def get_config(self): if self.dtype.kind == 'S': labels = [ensure_text(l) for l in self.labels] else: labels = self.labels config = dict(id=self.codec_id, labels=labels, dtype=self.dtype.str, astype=self.astype.str) return config
def json_loads(s: str) -> Dict[str, Any]: """Read JSON in a consistent way.""" return json.loads(ensure_text(s, 'ascii'))
def json_loads(s): """Read JSON in a consistent way.""" return json.loads(ensure_text(s, 'ascii'), cls=ZarrJsonDecoder)
def json_loads(s): """Read JSON in a consistent way.""" return json.loads(ensure_text(s, 'ascii'))