# Path: numcodecs/pickles.py
# class Pickle(Codec):
#     """Codec to encode data as as pickled bytes. Useful for encoding an array of Python string
#     objects.
# 
#     Parameters
#     ----------
#     protocol : int, defaults to pickle.HIGHEST_PROTOCOL
#         The protocol used to pickle data.
# 
#     Examples
#     --------
#     >>> import numcodecs as codecs
#     >>> import numpy as np
#     >>> x = np.array(['foo', 'bar', 'baz'], dtype='object')
#     >>> f = codecs.Pickle()
#     >>> f.decode(f.encode(x))
#     array(['foo', 'bar', 'baz'], dtype=object)
# 
#     See Also
#     --------
#     numcodecs.msgpacks.MsgPack
# 
#     """
# 
#     codec_id = 'pickle'
# 
#     def __init__(self, protocol=pickle.HIGHEST_PROTOCOL):
#         self.protocol = protocol
# 
#     def encode(self, buf):
#         return pickle.dumps(buf, protocol=self.protocol)
# 
#     def decode(self, buf, out=None):
#         buf = ensure_contiguous_ndarray(buf)
#         dec = pickle.loads(buf)
# 
#         if out is not None:
#             np.copyto(out, dec)
#             return out
#         else:
#             return dec
# 
#     def get_config(self):
#         return dict(id=self.codec_id,
#                     protocol=self.protocol)
# 
#     def __repr__(self):
#         return 'Pickle(protocol=%s)' % self.protocol
# 
# Path: numcodecs/tests/common.py
# def compare_arrays(arr, res, precision=None):
# def check_encode_decode(arr, codec, precision=None):
# def check_encode_decode_partial(arr, codec, precision=None):
# def assert_array_items_equal(res, arr):
# def check_encode_decode_array(arr, codec):
# def check_config(codec):
# def check_repr(stmt):
# def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, prefix=None):
# def check_err_decode_object_buffer(compressor):
# def check_err_encode_object_buffer(compressor):
# def check_max_buffer_size(codec):


import itertools
import sys
import numpy as np
import pytest
from numcodecs.pickles import Pickle
from numcodecs.tests.common import (check_config, check_repr, check_encode_decode_array,
                                    check_backwards_compatibility, greetings)



codecs = [Pickle(protocol=i) for i in range(5)]

# object array with strings
# object array with mix strings / nans
# object array with mix of string, int, float
# ...
arrays = [
    np.array(['foo', 'bar', 'baz'] * 300, dtype=object),
    np.array([['foo', 'bar', np.nan]] * 300, dtype=object),
    np.array(['foo', 1.0, 2] * 300, dtype=object),
    np.arange(1000, dtype='i4'),
    np.array(['foo', 'bar', 'baz'] * 300),
    np.array(['foo', ['bar', 1.0, 2], {'a': 'b', 'c': 42}] * 300, dtype=object),
    np.array(greetings * 100),
    np.array(greetings * 100, dtype=object),
]


def test_encode_decode():
    for arr, codec in itertools.product(arrays, codecs):
        check_encode_decode_array(arr, codec)


def test_config():
    codec = Pickle(protocol=-1)
    check_config(codec)
    for codec in codecs:

# Path: numcodecs/pickles.py
# class Pickle(Codec):
#     """Codec to encode data as as pickled bytes. Useful for encoding an array of Python string
#     objects.
# 
#     Parameters
#     ----------
#     protocol : int, defaults to pickle.HIGHEST_PROTOCOL
#         The protocol used to pickle data.
# 
#     Examples
#     --------
#     >>> import numcodecs as codecs
#     >>> import numpy as np
#     >>> x = np.array(['foo', 'bar', 'baz'], dtype='object')
#     >>> f = codecs.Pickle()
#     >>> f.decode(f.encode(x))
#     array(['foo', 'bar', 'baz'], dtype=object)
# 
#     See Also
#     --------
#     numcodecs.msgpacks.MsgPack
# 
#     """
# 
#     codec_id = 'pickle'
# 
#     def __init__(self, protocol=pickle.HIGHEST_PROTOCOL):
#         self.protocol = protocol
# 
#     def encode(self, buf):
#         return pickle.dumps(buf, protocol=self.protocol)
# 
#     def decode(self, buf, out=None):
#         buf = ensure_contiguous_ndarray(buf)
#         dec = pickle.loads(buf)
# 
#         if out is not None:
#             np.copyto(out, dec)
#             return out
#         else:
#             return dec
# 
#     def get_config(self):
#         return dict(id=self.codec_id,
#                     protocol=self.protocol)
# 
#     def __repr__(self):
#         return 'Pickle(protocol=%s)' % self.protocol
# 
# Path: numcodecs/tests/common.py
# def compare_arrays(arr, res, precision=None):
# def check_encode_decode(arr, codec, precision=None):
# def check_encode_decode_partial(arr, codec, precision=None):
# def assert_array_items_equal(res, arr):
# def check_encode_decode_array(arr, codec):
# def check_config(codec):
# def check_repr(stmt):
# def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, prefix=None):
# def check_err_decode_object_buffer(compressor):
# def check_err_encode_object_buffer(compressor):
# def check_max_buffer_size(codec):


# Path: numcodecs/tests/test_pickles.py
import itertools
import sys
import numpy as np
import pytest
from numcodecs.pickles import Pickle
from numcodecs.tests.common import (check_config, check_repr, check_encode_decode_array,
                                    check_backwards_compatibility, greetings)




codecs = [Pickle(protocol=i) for i in range(5)]

# object array with strings
# object array with mix strings / nans
# object array with mix of string, int, float
# ...
arrays = [
    np.array(['foo', 'bar', 'baz'] * 300, dtype=object),
    np.array([['foo', 'bar', np.nan]] * 300, dtype=object),
    np.array(['foo', 1.0, 2] * 300, dtype=object),
    np.arange(1000, dtype='i4'),
    np.array(['foo', 'bar', 'baz'] * 300),
    np.array(['foo', ['bar', 1.0, 2], {'a': 'b', 'c': 42}] * 300, dtype=object),
    np.array(greetings * 100),
    np.array(greetings * 100, dtype=object),
]


def test_encode_decode():
    for arr, codec in itertools.product(arrays, codecs):
        check_encode_decode_array(arr, codec)


def test_config():
    codec = Pickle(protocol=-1)
    check_config(codec)
    for codec in codecs:

        check_config(codec)