import numpy as np

import zarr
zarr.__version__

import numcodecs
numcodecs.__version__

"""
Explanation: Object arrays
See #212 for more information.
End of explanation
"""


z = zarr.empty(10, chunks=5, dtype=object, object_codec=numcodecs.MsgPack())
z

"""
Explanation: API changes in Zarr version 2.2
Creation of an object array requires providing new object_codec argument:
End of explanation
"""


z.info

z[0] = 'foo'
z[1] = b'bar'  # msgpack doesn't support bytes objects correctly
z[2] = 1
z[3] = [2, 4, 6, 'baz']
z[4] = {'a': 'b', 'c': 'd'}
a = z[:]
a

"""
Explanation: To maintain backwards compatibility with previously-created data, the object codec is treated as a filter and inserted as the first filter in the chain:
End of explanation
"""


z = zarr.empty(10, chunks=5, dtype=object)

"""
Explanation: If no object_codec is provided, a ValueError is raised:
End of explanation
"""


z = zarr.empty(10, chunks=5, dtype=object, filters=[numcodecs.MsgPack()])

"""
Explanation: For API backward-compatibility, if object codec is provided via filters, issue a warning but don't raise an error.
End of explanation
"""


z = zarr.empty(10, chunks=5, dtype=object, object_codec=numcodecs.MsgPack())
z._filters = None  # try to live dangerously, manually wipe filters

z[0] = 'foo'

"""
Explanation: If a user tries to subvert the system and create an object array with no object codec, a runtime check is added to ensure no object arrays are passed down to the compressor (which could lead to nasty errors and/or segfaults):
End of explanation
"""


from numcodecs.tests.common import greetings
z = zarr.array(greetings, chunks=5, dtype=object, object_codec=numcodecs.MsgPack())
z[:]

z._filters = []  # try to live dangerously, manually wipe filters
z[:]

"""
Explanation: Here is another way to subvert the system, wiping filters after storing some data. To cover this case a runtime check is added to ensure no object arrays are handled inappropriately during decoding (which could lead to nasty errors and/or segfaults).
End of explanation
"""


