Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ensure_text in JSON codecs #207

Merged
merged 1 commit into from Nov 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions numcodecs/json.py
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, division
import codecs
import json as _json
import textwrap

Expand All @@ -9,7 +8,7 @@


from .abc import Codec
from .compat import ensure_contiguous_ndarray
from .compat import ensure_text


class JSON(Codec):
Expand Down Expand Up @@ -64,8 +63,7 @@ def encode(self, buf):
return self._encoder.encode(items).encode(self._text_encoding)

def decode(self, buf, out=None):
buf = ensure_contiguous_ndarray(buf)
items = self._decoder.decode(codecs.decode(buf, self._text_encoding))
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:
Expand Down Expand Up @@ -126,8 +124,7 @@ def encode(self, buf):
return self._encoder.encode(items).encode(self._text_encoding)

def decode(self, buf, out=None):
buf = ensure_contiguous_ndarray(buf)
items = self._decoder.decode(codecs.decode(buf, self._text_encoding))
items = self._decoder.decode(ensure_text(buf, self._text_encoding))
dec = np.array(items[:-1], dtype=items[-1])
if out is not None:
np.copyto(out, dec)
Expand Down