Python library for serializing any arbitrary object graph into JSON. It can take almost any Python object and turn the object into JSON. Additionally, it can reconstitute the object back into Python.

Overview
https://dev.azure.com/jaraco/jsonpickle/_apis/build/status/jaraco.jsonpickle?branchName=master https://readthedocs.org/projects/jsonpickle/badge/?version=latest travis BSD

jsonpickle

jsonpickle is a library for the two-way conversion of complex Python objects and JSON. jsonpickle builds upon the existing JSON encoders, such as simplejson, json, and demjson.

For complete documentation, please visit the jsonpickle documentation.

Bug reports and merge requests are encouraged at the jsonpickle repository on github.

jsonpickle supports Python 2.7 and Python 3.4 or greater.

WARNING: jsonpickle can execute arbitrary Python code. Do not load jsonpickles from untrusted / unauthenticated sources.

Why jsonpickle?

Data serialized with python's pickle (or cPickle or dill) is not easily readable outside of python. Using the json format, jsonpickle allows simple data types to be stored in a human-readable format, and more complex data types such as numpy arrays and pandas dataframes, to be machine-readable on any platform that supports json. E.g., unlike pickled data, jsonpickled data stored in an Amazon S3 bucket is indexible by Amazon's Athena.

Install

Install from pip for the latest stable release:

pip install jsonpickle

Install from github for the latest changes:

pip install git+https://github.com/jsonpickle/jsonpickle.git

If you have the files checked out for development:

git clone https://github.com/jsonpickle/jsonpickle.git
cd jsonpickle
python setup.py develop

Numpy Support

jsonpickle includes a built-in numpy extension. If would like to encode sklearn models, numpy arrays, and other numpy-based data then you must enable the numpy extension by registering its handlers:

>>> import jsonpickle.ext.numpy as jsonpickle_numpy
>>> jsonpickle_numpy.register_handlers()

Pandas Support

jsonpickle includes a built-in pandas extension. If would like to encode pandas DataFrame or Series objects then you must enable the pandas extension by registering its handlers:

>>> import jsonpickle.ext.pandas as jsonpickle_pandas
>>> jsonpickle_pandas.register_handlers()

jsonpickleJS

jsonpickleJS is a javascript implementation of jsonpickle by Michael Scott Cuthbert. jsonpickleJS can be extremely useful for projects that have parallel data structures between Python and Javascript.

License

Licensed under the BSD License. See COPYING for details. See jsonpickleJS/LICENSE for details about the jsonpickleJS license.

Development

Use make to run the unit tests:

make test

pytest is used to run unit tests internally.

A tox target is provided to run tests using tox. Setting multi=1 tests using all installed and supported Python versions:

make tox
make tox multi=1

jsonpickle itself has no dependencies beyond the Python stdlib. tox is required for testing when using the tox test runner only.

The testing requirements are specified in requirements-dev.txt. It is recommended to create a virtualenv and run tests from within the virtualenv, or use a tool such as vx to activate the virtualenv without polluting the shell environment:

python3 -mvenv env3x
vx env3x pip install --requirement requirements-dev.txt
vx env3x make test

jsonpickle supports multiple Python versions, so using a combination of multiple virtualenvs and tox is useful in order to catch compatibility issues when developing.

Comments
  • Encoding byte strings in Python 3 causes infinite recursion

    Encoding byte strings in Python 3 causes infinite recursion

    >>> jsonpickle.encode(b'foo')
    ---------------------------------------------------------------------------
    RuntimeError                              Traceback (most recent call last)
    <ipython-input-7-5e089e18bf41> in <module>()
    ----> 1 jsonpickle.encode(b'foo')
    
    /Users/ivansmirnov/dev/jsonpickle/jsonpickle/__init__.py in encode(value, unpicklable, make_refs, keys, max_depth, backend, warn, max_iter)
        129                           keys=keys,
        130                           max_depth=max_depth,
    --> 131                           warn=warn)
        132 
        133 
    
    /Users/ivansmirnov/dev/jsonpickle/jsonpickle/pickler.py in encode(value, unpicklable, make_refs, keys, max_depth, reset, backend, warn, context, max_iter)
         39                           warn=warn,
         40                           max_iter=max_iter)
    ---> 41     return backend.encode(context.flatten(value, reset=reset))
         42 
         43 
    
    /Users/ivansmirnov/dev/jsonpickle/jsonpickle/pickler.py in flatten(self, obj, reset)
        139         if reset:
        140             self.reset()
    --> 141         return self._flatten(obj)
        142 
        143     def _flatten(self, obj):
    
    /Users/ivansmirnov/dev/jsonpickle/jsonpickle/pickler.py in _flatten(self, obj)
        143     def _flatten(self, obj):
        144         self._push()
    --> 145         return self._pop(self._flatten_obj(obj))
        146 
        147     def _flatten_obj(self, obj):
    
    /Users/ivansmirnov/dev/jsonpickle/jsonpickle/pickler.py in _flatten_obj(self, obj)
        159             return None
        160 
    --> 161         return flatten_func(obj)
        162 
        163     def _list_recurse(self, obj):
    
    /Users/ivansmirnov/dev/jsonpickle/jsonpickle/pickler.py in _ref_obj_instance(self, obj)
        214             # We've never seen this object so return its
        215             # json representation.
    --> 216             return self._flatten_obj_instance(obj)
        217         # We've seen this object before so place an object
        218         # reference tag in the data. This avoids infinite recursion
    
    ...
    
    /Users/ivansmirnov/dev/jsonpickle/jsonpickle/pickler.py in _flatten(self, obj)
        143     def _flatten(self, obj):
        144         self._push()
    --> 145         return self._pop(self._flatten_obj(obj))
        146 
        147     def _flatten_obj(self, obj):
    
    /Users/ivansmirnov/dev/jsonpickle/jsonpickle/pickler.py in _flatten_obj(self, obj)
        147     def _flatten_obj(self, obj):
        148         self._seen.append(obj)
    --> 149         max_reached = self._depth == self._max_depth
        150 
        151         if max_reached or (not self.make_refs and id(obj) in self._objs):
    
    RuntimeError: maximum recursion depth exceeded in comparison
    
    opened by aldanor 30
  • Fails to built with numpy 1.20.0, py 3.10 or 3.9.

    Fails to built with numpy 1.20.0, py 3.10 or 3.9.

    https://bugzilla.redhat.com/show_bug.cgi?id=1913439

    python-jsonpickle fails to build with Python 3.10.0a4 and Python 3.9.1. This seems related to the updated NumPy.

    ______________________ NumpyTestCase.test_dtype_roundtrip ______________________

    self = <numpy_test.NumpyTestCase testMethod=test_dtype_roundtrip>

    def test_dtype_roundtrip(self):
        if self.should_skip:
            return self.skip('numpy is not importable')
        dtypes = [
            np.int,
            np.float,
            np.complex,
            np.int32,
            np.str,
            np.object,
            np.unicode,
            np.dtype('f4,i4,f2,i1'),
            np.dtype(('f4', 'i4'), ('f2', 'i1')),
            np.dtype('1i4', align=True),
            np.dtype('M8[7D]'),
            np.dtype(
                {
                    'names': ['f0', 'f1', 'f2'],
                    'formats': ['<u4', '<u2', '<u2'],
                    'offsets': [0, 0, 2],
                },
                align=True,
            ),
        ]
    
        if not PY2:
            dtypes.extend(
                [
                    np.dtype([('f0', 'i4'), ('f2', 'i1')]),
                    np.dtype(
                        [
                            (
                                'top',
                                [
                                    ('tiles', ('>f4', (64, 64)), (1,)),
                                    ('rtile', '>f4', (64, 36)),
                                ],
                                (3,),
                            ),
                            (
                                'bottom',
                                [
                                    ('bleft', ('>f4', (8, 64)), (1,)),
                                    ('bright', '>f4', (8, 36)),
                                ],
                            ),
                        ]
                    ),
                ]
            )
    
        for dtype in dtypes:
    
          self.assertEqual(self.roundtrip(dtype), dtype)
    

    tests/numpy_test.py:95:


    /usr/lib64/python3.10/site-packages/numpy/core/_internal.py:61: in _usefields names, formats, offsets, titles = _makenames_list(adict, align)


    adict = {'dtype': "[('f0', '<f4'), ('f1', '<i4'), ('f2', '<f2'), ('f3', 'i1')]", 'py/object': 'numpy.dtype[void]'} align = 0

    def _makenames_list(adict, align):
        allfields = []
    
        for fname, obj in adict.items():
            n = len(obj)
            if not isinstance(obj, tuple) or n not in (2, 3):
    
              raise ValueError("entry not a 2- or 3- tuple")
    

    E ValueError: entry not a 2- or 3- tuple

    /usr/lib64/python3.10/site-packages/numpy/core/_internal.py:31: ValueError

    wishlist compatibility 
    opened by limburgher 19
  • scikit learn decision tree gets unpickled as dictionary

    scikit learn decision tree gets unpickled as dictionary

    I am having a problem unpickling scikit-learn deicsion trees. Example code:

    import numpy as np
    import jsonpickle
    import jsonpickle.ext.numpy as jsonpickle_numpy
    from sklearn.tree import DecisionTreeClassifier
    
    #  create data
    np.random.seed(13)
    x = np.random.randint(low=0, high = 10, size = 12)
    X = x.reshape(4, 3)
    Y = np.random.randint(low=0, high=2, size=4)
    Y.reshape(-1,1)
    
    # train model
    clf = DecisionTreeClassifier(max_depth=1)
    clf.fit(X, Y)
    
    # freeze and thaw
    jsonpickle_numpy.register_handlers()
    p = jsonpickle.pickler.Pickler()
    u = jsonpickle.unpickler.Unpickler()
    j = p.flatten(clf)
    clf1 = u.restore(json.loads(json.dumps(p.flatten(clf))))
    
    # predict from thawed
    xx = np.array([1, 2, 3])
    xx = xx.reshape(1,-1)
    clf1.predict(xx)
    
    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-15-4e5a1309ca7a> in <module>()
         27 xx = np.array([1, 2, 3])
         28 xx = xx.reshape(1,-1)
    ---> 29 clf1.predict(xx)
    
    /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/tree/tree.pyc in predict(self, X, check_input)
        403 
        404         X = self._validate_X_predict(X, check_input)
    --> 405         proba = self.tree_.predict(X)
        406         n_samples = X.shape[0]
        407 
    
    AttributeError: 'dict' object has no attribute 'predict'
    

    On further inspection, the problem seems to be the following:

    print type(clf)
    print type(clf1)
    print type(clf.tree_)
    print type(clf1.tree_)
    
    <class 'sklearn.tree.tree.DecisionTreeClassifier'>
    <class 'sklearn.tree.tree.DecisionTreeClassifier'>
    <type 'sklearn.tree._tree.Tree'>
    <type 'dict'>
    

    i.e. the classifier object gets unpickled as the correct type, while the decision tree under clf.tree_ is getting unpickled as a dictionary. I confirned the same behavior with DecisionTreeRegressor and ensemble methods which use trees , for example GradientBoostingClassifier.

    opened by nikos-daniilidis 17
  • jsonpickle and numpy float enter recursive loop and raise RuntimeError

    jsonpickle and numpy float enter recursive loop and raise RuntimeError

    Using jsonpickle on a pure-Python float works fine, doing the same on a numpy.float_ causes a RuntimeError to be raised due to a recursion limit. The same behaviour can be seen if using numpy.int_ and numpy.bool_.

    This sample code reproduces the bug:

    """jsonpickle fails with recursion error on numpy floats"""
    # Using Python 3.4 via Anaconda
    import jsonpickle  # version == 0.8.0
    import numpy as np  # __version__ == 1.9.1
    
    # make a numpy float object
    f = np.float_(42)
    
    # encoding a pure-Python float works correctly
    f_float_encoded = jsonpickle.encode(float(f))
    
    # fails with:
    # RuntimeError: maximum recursion depth exceeded while calling a Python object
    f_numpy_encodoed = jsonpickle.encode(f)  # raises RuntimeError
    

    Tail end of the stack trace:

    /home/ian/anaconda/envs/elevate_direct/lib/python3.4/site-packages/jsonpickle/pickler.py in _ref_obj_instance(self, obj)
        211             # We've never seen this object so return its
        212             # json representation.
    --> 213             return self._flatten_obj_instance(obj)
        214         # We've seen this object before so place an object
        215         # reference tag in the data. This avoids infinite recursion
    
    /home/ian/anaconda/envs/elevate_direct/lib/python3.4/site-packages/jsonpickle/pickler.py in _flatten_obj_instance(self, obj)
        287 
        288             if has_getnewargs:
    --> 289                 data[tags.NEWARGS] = self._flatten(obj.__getnewargs__())
        290 
        291             if has_getinitargs:
    
    /home/ian/anaconda/envs/elevate_direct/lib/python3.4/site-packages/jsonpickle/pickler.py in _flatten(self, obj)
        143     def _flatten(self, obj):
        144         self._push()
    --> 145         return self._pop(self._flatten_obj(obj))
        146 
        147     def _flatten_obj(self, obj):
    
    /home/ian/anaconda/envs/elevate_direct/lib/python3.4/site-packages/jsonpickle/pickler.py in _flatten_obj(self, obj)
        159             return None
        160 
    --> 161         return flatten_func(obj)
        162 
        163     def _list_recurse(self, obj):
    
    /home/ian/anaconda/envs/elevate_direct/lib/python3.4/site-packages/jsonpickle/pickler.py in <lambda>(obj)
        182             if not self.unpicklable:
        183                 return list_recurse
    --> 184             return lambda obj: {tags.TUPLE: [self._flatten(v) for v in obj]}
        185 
        186         if util.is_set(obj):
    
    /home/ian/anaconda/envs/elevate_direct/lib/python3.4/site-packages/jsonpickle/pickler.py in <listcomp>(.0)
        182             if not self.unpicklable:
        183                 return list_recurse
    --> 184             return lambda obj: {tags.TUPLE: [self._flatten(v) for v in obj]}
        185 
        186         if util.is_set(obj):
    
    /home/ian/anaconda/envs/elevate_direct/lib/python3.4/site-packages/jsonpickle/pickler.py in _flatten(self, obj)
        143     def _flatten(self, obj):
        144         self._push()
    --> 145         return self._pop(self._flatten_obj(obj))
        146 
        147     def _flatten_obj(self, obj):
    
    /home/ian/anaconda/envs/elevate_direct/lib/python3.4/site-packages/jsonpickle/pickler.py in _flatten_obj(self, obj)
        159             return None
        160 
    --> 161         return flatten_func(obj)
        162 
        163     def _list_recurse(self, obj):
    
    /home/ian/anaconda/envs/elevate_direct/lib/python3.4/site-packages/jsonpickle/pickler.py in _ref_obj_instance(self, obj)
        211             # We've never seen this object so return its
        212             # json representation.
    --> 213             return self._flatten_obj_instance(obj)
        214         # We've seen this object before so place an object
        215         # reference tag in the data. This avoids infinite recursion
    
    /home/ian/anaconda/envs/elevate_direct/lib/python3.4/site-packages/jsonpickle/pickler.py in _flatten_obj_instance(self, obj)
        226         has_getnewargs = hasattr(obj, '__getnewargs__')
        227         has_getinitargs = hasattr(obj, '__getinitargs__')
    --> 228         has_reduce, has_reduce_ex = util.has_reduce(obj)
        229 
        230         # Support objects with __getstate__(); this ensures that
    
    /home/ian/anaconda/envs/elevate_direct/lib/python3.4/site-packages/jsonpickle/util.py in has_reduce(obj)
        317     """
        318 
    --> 319     if not is_reducible(obj) or is_type(obj):
        320         return (False, False)
        321 
    
    /home/ian/anaconda/envs/elevate_direct/lib/python3.4/site-packages/jsonpickle/util.py in is_reducible(obj)
        286     __reduce__ methods used
        287     """
    --> 288     return (not (is_list(obj) or is_list_like(obj) or is_primitive(obj) or
        289                  is_dictionary(obj) or is_sequence(obj) or is_set(obj) or is_tuple(obj) or
        290                  is_dictionary_subclass(obj) or is_sequence_subclass(obj) or is_noncomplex(obj)
    
    /home/ian/anaconda/envs/elevate_direct/lib/python3.4/site-packages/jsonpickle/util.py in is_list(obj)
        108     True
        109     """
    --> 110     return type(obj) is list
        111 
        112 
    
    RuntimeError: maximum recursion depth exceeded while calling a Python object
    
    opened by ianozsvald 17
  • ndarray views and binary encoding

    ndarray views and binary encoding

    This PR adds support for ndarray views, or tracking references inside nd-arrays. In a nutshell:

            # the fact that this works is a defining feature of this package
            row = [1, 2, 3]
            nested_list = [row, row]
            nested_list_ = roundtrip(nested_list)
            nested_list_[0][0] = -1
            assert nested_list_[1][0] == -1
    
            # so it would be kinda nice if this worked the same way; which it does as per this PR
            row = np.arange(3)
            jagged_array = [row, row[:]]
            jagged_array_ = roundtrip(jagged_array)
            jagged_array_[0][0] = -1
            assert jagged_array_[1][0] == -1
    

    Also, arrays with more elements than a given threshold are encoded as (optionally) compressed b64. This is a much simpler and somewhat separate issue; so perhaps it does not belong in this PR, though personally I would really like to see that merged as well. For big arrays, the computational overhead of conversions to string are huge, and the human-readability argument for them is pretty much void.

    Feedback is very much welcome!

    opened by EelcoHoogendoorn 16
  • Test failures with Python 3.11

    Test failures with Python 3.11

    Hello. We are trying to rebuild jsonpickle in Fedora with Python 3.11.0b3. Currently, there are various test failures in our build environment, but I can reproduce many with plan tox. To avoid dealing with compilation issues of scipy and pandas, I've reduced the tests like this:

    diff --git a/setup.cfg b/setup.cfg
    index f068a00..7712763 100644
    --- a/setup.cfg
    +++ b/setup.cfg
    @@ -57,14 +57,7 @@ testing =
         pytest-cov
     
         # local
    -    ecdsa
    -    feedparser
    -    gmpy2
    -    numpy
    -    pandas
    -    pymongo
    -    scikit-learn
    -    sqlalchemy
    +    pytz
    

    And run tox -e py311 -- -k 'not (test_thing_with_module or test_thing_with_submodule)' tests 2>&1 | tee tox_output.

    (test_thing_with_module and test_thing_with_submodule hang for me when reproducing like this, so I've deselected them)

    This is the output:

    WARNING: The wheel package is not available.
    py311 develop-inst-noop: .../jsonpickle
    py311 installed: attrs==21.4.0,black==22.3.0,click==8.1.3,coverage==6.4.1,docutils==0.18.1,flake8==4.0.1,importlib-metadata==4.11.4,iniconfig==1.1.1,-e git+ssh://[email protected]/jsonpickle/jsonpickle.git@c2fdc01887d6173fdd46e0d322832b906ee80e22#egg=jsonpickle,mccabe==0.6.1,mypy-extensions==0.4.3,packaging==21.3,pathspec==0.9.0,pep517==0.12.0,platformdirs==2.5.2,pluggy==1.0.0,py==1.11.0,pycodestyle==2.8.0,pyflakes==2.4.0,pyparsing==3.0.9,pytest==7.1.2,pytest-black==0.3.12,pytest-black-multipy==1.0.1,pytest-checkdocs==2.7.1,pytest-cov==3.0.0,pytest-flake8==1.1.1,pytz==2022.1,toml==0.10.2,tomli==2.0.1,zipp==3.8.0
    py311 run-test-pre: PYTHONHASHSEED='573023578'
    py311 run-test: commands[0] | pytest -k 'not (test_thing_with_module or test_thing_with_submodule)' tests
    ============================= test session starts ==============================
    platform linux -- Python 3.11.0b3, pytest-7.1.2, pluggy-1.0.0
    cachedir: .tox/py311/.pytest_cache
    rootdir: .../jsonpickle, configfile: pytest.ini
    plugins: checkdocs-2.7.1, flake8-1.1.1, cov-3.0.0, black-0.3.12, black-multipy-1.0.1
    collected 296 items / 3 deselected / 6 skipped / 293 selected
    
    tests/backend_test.py s.....ssssssssss                                   [  5%]
    tests/benchmark.py s                                                     [  5%]
    tests/bson_test.py sssssss                                               [  8%]
    tests/collections_test.py sFFF.FF                                        [ 10%]
    tests/datetime_test.py s................                                 [ 16%]
    tests/document_test.py sF                                                [ 17%]
    tests/ecdsa_test.py sE                                                   [ 17%]
    tests/feedparser_test.py ss                                              [ 18%]
    tests/handler_test.py s......                                            [ 20%]
    tests/helper.py s                                                        [ 21%]
    tests/jsonpickle_test.py s......FFFF........................F.F.......F. [ 37%]
    ................F..F.............................FF........F             [ 57%]
    tests/numpy_test.py s                                                    [ 58%]
    tests/object_test.py s...........F..FF........FF..FFF.....FFFFFF.....F.. [ 75%]
    .F....XXX......F.........                                                [ 83%]
    tests/pandas_test.py s                                                   [ 84%]
    tests/sklearn_test.py s                                                  [ 84%]
    tests/sqlalchemy_test.py ssss                                            [ 86%]
    tests/stdlib_test.py s...                                                [ 87%]
    tests/util_test.py s.................................                    [ 98%]
    tests/wizard_test.py sF.                                                 [100%]
    
    ==================================== ERRORS ====================================
    ________________ ERROR at setup of EcdsaTestCase.test_roundtrip ________________
    ...
    =================================== FAILURES ===================================
    ______________________________ test_dict_no_cycle ______________________________
    
        def test_dict_no_cycle():
            g = Group('group')
            c1 = C(42)
            g.elements.append(c1)
            c2 = C(67)
            g.elements.append(c2)
            c1.add(c2, 'a')  # points to c2, which does not point to anything
        
            assert c2 in c1.plain
            assert c2 in c1.plain_ordered
            assert c2 in c1.plain_default
        
            gu = pickle_and_unpickle(g)
            c1u = gu.elements[0]
            c2u = gu.elements[1]
        
            # check existence of keys directly
            assert c2u in c1u.plain.keys()
            assert c2u in c1u.plain_ordered.keys()
    >       assert c2u in c1u.plain_default.keys()
    E       AttributeError: 'NoneType' object has no attribute 'keys'
    
    tests/collections_test.py:139: AttributeError
    _____________________________ test_dict_self_cycle _____________________________
    
        def test_dict_self_cycle():
            g = Group('group')
            c1 = C(42)
            g.elements.append(c1)
            c2 = C(67)
            g.elements.append(c2)
            c1.add(c1, 'a')  # cycle to itself
            c1.add(c2, 'b')  # c2 does not point to itself nor c1
        
            assert c1 in c1.plain
            assert c1 in c1.plain_ordered
            assert c1 in c1.plain_default
        
    >       gu = pickle_and_unpickle(g)
    
    tests/collections_test.py:171: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    tests/collections_test.py:117: in pickle_and_unpickle
        return jsonpickle.decode(encoded, keys=True)
    jsonpickle/unpickler.py:88: in decode
        return context.restore(data, reset=reset, classes=classes)
    jsonpickle/unpickler.py:362: in restore
        value = self._restore(obj)
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:771: in _restore_object
        return self._restore_object_instance(obj, cls, class_name)
    jsonpickle/unpickler.py:747: in _restore_object_instance
        instance = self._restore_object_instance_variables(obj, instance)
    jsonpickle/unpickler.py:693: in _restore_object_instance_variables
        instance = self._restore_state(obj, instance)
    jsonpickle/unpickler.py:652: in _restore_state
        state = self._restore(obj[tags.STATE])
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:798: in _restore_dict
        data[k] = self._restore(v)
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:431: in _restore_list
        children = [self._restore(v) for v in obj]
    jsonpickle/unpickler.py:431: in <listcomp>
        children = [self._restore(v) for v in obj]
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:771: in _restore_object
        return self._restore_object_instance(obj, cls, class_name)
    jsonpickle/unpickler.py:747: in _restore_object_instance
        instance = self._restore_object_instance_variables(obj, instance)
    jsonpickle/unpickler.py:693: in _restore_object_instance_variables
        instance = self._restore_state(obj, instance)
    jsonpickle/unpickler.py:663: in _restore_state
        instance = self._restore_from_dict(state, instance, ignorereserved=False)
    jsonpickle/unpickler.py:612: in _restore_from_dict
        value = self._restore(v)
    jsonpickle/unpickler.py:343: in _restore
        restore = self._restore_tags(obj)
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    self = <jsonpickle.unpickler.Unpickler object at 0x7f269470e050>
    obj = <[KeyError(C(42)) raised in repr()] OrderedDict object at 0x7f26946f8dc0>
    
        def _restore_tags(self, obj):
            try:
    >           if not tags.RESERVED <= set(obj) and not type(obj) in (list, dict):
    E           KeyError: C(42)
    
    jsonpickle/unpickler.py:832: KeyError
    ____________________________ test_dict_mutual_cycle ____________________________
    
        def test_dict_mutual_cycle():
            g = Group('group')
            c1 = C(42)
            g.elements.append(c1)
            c2 = C(67)
            g.elements.append(c2)
        
            c1.add(c2, 'a')  # points to c2, which points to c1, forming cycle
            c2.add(c1, 'a')  # points to c1 in order to form cycle
        
            assert c2 in c1.plain
            assert c2 in c1.plain_ordered
            assert c2 in c1.plain_default
        
            assert c1 in c2.plain
            assert c1 in c2.plain_ordered
            assert c1 in c2.plain_default
        
            gu = pickle_and_unpickle(g)
            c1u = gu.elements[0]
            c2u = gu.elements[1]
        
            # check existence of keys directly
            # key c2u
            assert c2u in c1u.plain.keys()
            assert c2u in c1u.plain_ordered.keys()
    >       assert c2u in c1u.plain_default.keys()
    E       AttributeError: 'NoneType' object has no attribute 'keys'
    
    tests/collections_test.py:252: AttributeError
    _____________________________ test_set_self_cycle ______________________________
    
        def test_set_self_cycle():
            g = Group('group')
            d1 = D(42)
            g.elements.append(d1)
            d2 = D(67)
            g.elements.append(d2)
            d1.add(d1)  # cycle to itself
            d1.add(d2)  # d1 also points to d2, but d2 does not point to d1
        
            assert d1 in d1.plain
        
            gu = pickle_and_unpickle(g)
            d1u = gu.elements[0]
            d2u = gu.elements[1]
            assert d2u is not None
        
            # check element directly
    >       assert d1u in d1u.plain
    E       assert D(42) in {D(42), D(67)}
    E        +  where {D(42), D(67)} = D(42).plain
    
    tests/collections_test.py:335: AssertionError
    ____________________________ test_set_mutual_cycle _____________________________
    
        def test_set_mutual_cycle():
            g = Group('group')
            d1 = D(42)
            g.elements.append(d1)
            d2 = D(67)
            g.elements.append(d2)
            d1.add(d2)  # points to d2, which points to d1, forming cycle
            d2.add(d1)  # points to d1 in order to form cycle
        
            assert d2 in d1.plain
            assert d1 in d2.plain
        
            gu = pickle_and_unpickle(g)
            d1u = gu.elements[0]
            d2u = gu.elements[1]
        
            # check element directly
            # succeeds because d2u added to d1u after __setstate__
            assert d2u in d1u.plain
    >       assert d1u in d2u.plain
    E       assert D(42) in {D(42)}
    E        +  where {D(42)} = D(67).plain
    
    tests/collections_test.py:361: AssertionError
    ________________________ DocumentTestCase.test_cyclical ________________________
    
    self = <document_test.DocumentTestCase testMethod=test_cyclical>
    
        def test_cyclical(self):
            """Test that we can pickle cyclical data structure
        
            This test is ensures that we can reference objects which
            first appear within a list (in other words, not a top-level
            object or attribute).  Later children will reference that
            object through its "_parent" field.
        
            This makes sure that we handle this case correctly.
        
            """
            document = Document('My Document')
            section1 = Section('Section 1')
            section2 = Section('Section 2')
            question1 = Question('Question 1')
            question2 = Question('Question 2')
            question3 = Question('Question 3')
            question4 = Question('Question 4')
        
            document.add_child(section1)
            document.add_child(section2)
            section1.add_child(question1)
            section1.add_child(question2)
            section2.add_child(question3)
            section2.add_child(question4)
        
            pickled = jsonpickle.encode(document)
            unpickled = jsonpickle.decode(pickled)
        
    >       self.assertEqual(str(document), str(unpickled))
    
    tests/document_test.py:90: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    tests/document_test.py:31: in __str__
        ret_str += repr(c)
    tests/document_test.py:57: in __repr__
        return self.__str__()
    tests/document_test.py:53: in __str__
        ret_str += repr(c)
    tests/document_test.py:43: in __repr__
        return self.__str__()
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    self = <[AttributeError("'list' object has no attribute '_name'") raised in repr()] Question object at 0x7f2694753cd0>
    
        def __str__(self):
    >       return 'Question "%s", parent: "%s"\n' % (self._name, self._parent._name)
    E       AttributeError: 'list' object has no attribute '_name'
    
    tests/document_test.py:40: AttributeError
    _________________________ PicklingTestCase.test_class __________________________
    
    self = <jsonpickle_test.PicklingTestCase testMethod=test_class>
    
        def test_class(self):
            inst = Thing('test name')
            inst.child = Thing('child name')
        
            flattened = self.pickler.flatten(inst)
    >       self.assertEqual('test name', flattened['name'])
    E       KeyError: 'name'
    
    tests/jsonpickle_test.py:300: KeyError
    ____________________ PicklingTestCase.test_class_reference _____________________
    
    self = <jsonpickle_test.PicklingTestCase testMethod=test_class_reference>
    
        def test_class_reference(self):
            """This test ensures that users can store references to classes."""
            obj = Thing('object-with-class-reference')
        
            # reference the 'Thing' class (not an instance of the class)
            obj.classref = Thing
        
            flattened = self.pickler.flatten(obj)
    >       self.assertEqual(flattened['classref'], {tags.TYPE: 'jsonpickle_test.Thing'})
    E       KeyError: 'classref'
    
    tests/jsonpickle_test.py:424: KeyError
    _______________________ PicklingTestCase.test_classdict ________________________
    
    self = <jsonpickle_test.PicklingTestCase testMethod=test_classdict>
    
        def test_classdict(self):
            dict = {'k1': Thing('one'), 'k2': Thing('two'), 'k3': 3}
        
            flattened = self.pickler.flatten(dict)
    >       self.assertEqual('one', flattened['k1']['name'])
    E       KeyError: 'name'
    
    tests/jsonpickle_test.py:329: KeyError
    _______________________ PicklingTestCase.test_classlist ________________________
    
    self = <jsonpickle_test.PicklingTestCase testMethod=test_classlist>
    
        def test_classlist(self):
            array = [Thing('one'), Thing('two'), 'a string']
        
            flattened = self.pickler.flatten(array)
    >       self.assertEqual('one', flattened[0]['name'])
    E       KeyError: 'name'
    
    tests/jsonpickle_test.py:314: KeyError
    _____________________ PicklingTestCase.test_type_reference _____________________
    
    self = <jsonpickle_test.PicklingTestCase testMethod=test_type_reference>
    
        def test_type_reference(self):
            """This test ensures that users can store references to types."""
            obj = Thing('object-with-type-reference')
        
            # reference the built-in 'object' type
            obj.typeref = object
        
            flattened = self.pickler.flatten(obj)
    >       self.assertEqual(flattened['typeref'], {tags.TYPE: 'builtins.object'})
    E       KeyError: 'typeref'
    
    tests/jsonpickle_test.py:411: KeyError
    __________________ PicklingTestCase.test_unpickler_on_missing __________________
    
    self = <jsonpickle_test.PicklingTestCase testMethod=test_unpickler_on_missing>
    
        def test_unpickler_on_missing(self):
            class SimpleClass(object):
                def __init__(self, i):
                    self.i = i
        
            frozen = jsonpickle.encode(SimpleClass(4))
            del SimpleClass
        
            # https://docs.python.org/3/library/warnings.html#testing-warnings
        
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter("always")
                jsonpickle.decode(frozen, on_missing='warn')
                self.assertTrue(issubclass(w[-1].category, UserWarning))
                self.assertTrue(
                    "Unpickler._restore_object could not find" in str(w[-1].message)
                )
        
                jsonpickle.decode(frozen, on_missing=on_missing_callback)
                self.assertTrue(issubclass(w[-1].category, RuntimeWarning))
                self.assertTrue("The unpickler couldn't find" in str(w[-1].message))
        
    >       self.assertTrue(
                jsonpickle.decode(frozen, on_missing='ignore')
                == {
                    'py/object': 'jsonpickle_test.PicklingTestCase.test_unpickler_on_missing.<locals>.SimpleClass',
                    'i': 4,
                }
            )
    E       AssertionError: False is not true
    
    tests/jsonpickle_test.py:522: AssertionError
    ____________________ JSONPickleTestCase.test_dict_subclass _____________________
    
    self = <jsonpickle_test.JSONPickleTestCase testMethod=test_dict_subclass>
    
        def test_dict_subclass(self):
            obj = UserDict()
            obj.valid = True
            obj.s = 'string'
            obj.d = 'd_string'
            obj['d'] = {}
            obj['s'] = 'test'
            pickle = jsonpickle.encode(obj)
            actual = jsonpickle.decode(pickle)
        
            self.assertEqual(type(actual), UserDict)
            self.assertTrue('d' in actual)
            self.assertTrue('s' in actual)
    >       self.assertTrue(hasattr(actual, 'd'))
    E       AssertionError: False is not true
    
    tests/jsonpickle_test.py:713: AssertionError
    __________________ JSONPickleTestCase.test_reference_to_list ___________________
    
    self = <jsonpickle_test.JSONPickleTestCase testMethod=test_reference_to_list>
    
        def test_reference_to_list(self):
            thing = Thing('parent')
            thing.a = [1]
            thing.b = thing.a
            thing.b.append(thing.a)
            thing.b.append([thing.a])
        
            encoded = jsonpickle.encode(thing)
    >       decoded = jsonpickle.decode(encoded)
    
    tests/jsonpickle_test.py:858: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    jsonpickle/unpickler.py:88: in decode
        return context.restore(data, reset=reset, classes=classes)
    jsonpickle/unpickler.py:362: in restore
        value = self._restore(obj)
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:771: in _restore_object
        return self._restore_object_instance(obj, cls, class_name)
    jsonpickle/unpickler.py:747: in _restore_object_instance
        instance = self._restore_object_instance_variables(obj, instance)
    jsonpickle/unpickler.py:693: in _restore_object_instance_variables
        instance = self._restore_state(obj, instance)
    jsonpickle/unpickler.py:663: in _restore_state
        instance = self._restore_from_dict(state, instance, ignorereserved=False)
    jsonpickle/unpickler.py:612: in _restore_from_dict
        value = self._restore(v)
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:431: in _restore_list
        children = [self._restore(v) for v in obj]
    jsonpickle/unpickler.py:431: in <listcomp>
        children = [self._restore(v) for v in obj]
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    E   RecursionError: maximum recursion depth exceeded in __instancecheck__
    !!! Recursion detected (same locals & position)
    ____________________ JSONPickleTestCase.test_refs_recursive ____________________
    
    self = <jsonpickle.unpickler.Unpickler object at 0x7f26943a5110>, obj = {}
    
        def _mkref(self, obj):
            obj_id = id(obj)
            try:
    >           self._obj_to_idx[obj_id]
    E           KeyError: 139803671999104
    
    jsonpickle/unpickler.py:419: KeyError
    
    During handling of the above exception, another exception occurred:
    
    self = <jsonpickle_test.JSONPickleTestCase testMethod=test_refs_recursive>
    
        def test_refs_recursive(self):
            """Test that complicated recursive refs work"""
        
            a = Thing('a')
            a.self_list = [Thing('0'), Thing('1'), Thing('2')]
            a.first = a.self_list[0]
            a.stuff = {a.first: a.first}
            a.morestuff = {a.self_list[1]: a.stuff}
        
            pickle = jsonpickle.encode(a, keys=True)
    >       b = jsonpickle.decode(pickle, keys=True)
    
    tests/jsonpickle_test.py:773: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    jsonpickle/unpickler.py:88: in decode
        return context.restore(data, reset=reset, classes=classes)
    jsonpickle/unpickler.py:362: in restore
        value = self._restore(obj)
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:771: in _restore_object
        return self._restore_object_instance(obj, cls, class_name)
    jsonpickle/unpickler.py:747: in _restore_object_instance
        instance = self._restore_object_instance_variables(obj, instance)
    jsonpickle/unpickler.py:693: in _restore_object_instance_variables
        instance = self._restore_state(obj, instance)
    jsonpickle/unpickler.py:663: in _restore_state
        instance = self._restore_from_dict(state, instance, ignorereserved=False)
    jsonpickle/unpickler.py:612: in _restore_from_dict
        value = self._restore(v)
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:798: in _restore_dict
        data[k] = self._restore(v)
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:782: in _restore_dict
        self._mkref(data)
    jsonpickle/unpickler.py:425: in _mkref
        self._namedict[self._refname()] = obj
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    self = <jsonpickle.unpickler.Unpickler object at 0x7f26943a5110>
    
        def _refname(self):
            """Calculates the name of the current location in the JSON stack.
        
            This is called as jsonpickle traverses the object structure to
            create references to previously-traversed objects.  This allows
            cyclical data structures such as doubly-linked lists.
            jsonpickle ensures that duplicate python references to the same
            object results in only a single JSON object definition and
            special reference tags to represent each reference.
        
            >>> u = Unpickler()
            >>> u._namestack = []
            >>> u._refname() == '/'
            True
            >>> u._namestack = ['a']
            >>> u._refname() == '/a'
            True
            >>> u._namestack = ['a', 'b']
            >>> u._refname() == '/a/b'
            True
        
            """
    >       return '/' + '/'.join(self._namestack)
    E       TypeError: sequence item 1: expected str instance, Thing found
    
    jsonpickle/unpickler.py:414: TypeError
    _______________ PicklingProtocol2TestCase.test_reduce_state_dict _______________
    
    self = <jsonpickle_test.PicklingProtocol2TestCase testMethod=test_reduce_state_dict>
    
        def test_reduce_state_dict(self):
            """Test reduce with the optional state argument set,
            on an object with a __dict__, and no __setstate__"""
        
            instance = PickleProtocol2ReduceTupleState(5)
            encoded = jsonpickle.encode(instance)
            decoded = jsonpickle.decode(encoded)
    >       self.assertEqual(decoded.argval, 'yam')
    E       AssertionError: 5 != 'yam'
    
    tests/jsonpickle_test.py:1372: AssertionError
    _____________ PicklingProtocol2TestCase.test_reduce_state_no_dict ______________
    
    self = <jsonpickle_test.PicklingProtocol2TestCase testMethod=test_reduce_state_no_dict>
    
        def test_reduce_state_no_dict(self):
            """Test reduce with the optional state argument set,
            on an object with no __dict__, and no __setstate__"""
        
            instance = PickleProtocol2ReduceTupleStateSlots(5)
            encoded = jsonpickle.encode(instance)
            decoded = jsonpickle.decode(encoded)
    >       self.assertEqual(decoded.argval, 'yam')
    E       AssertionError: 5 != 'yam'
    
    tests/jsonpickle_test.py:1361: AssertionError
    _______________________ test_repeat_objects_are_expanded _______________________
    
        def test_repeat_objects_are_expanded():
            """Ensure that all objects are present in the json output"""
            # When references are disabled we should create expanded copies
            # of any object that appears more than once in the object stream.
            alice = Thing('alice')
            bob = Thing('bob')
            alice.child = bob
        
            car = Thing('car')
            car.driver = alice
            car.owner = alice
            car.passengers = [alice, bob]
        
            pickler = jsonpickle.Pickler(make_refs=False)
            flattened = pickler.flatten(car)
        
    >       assert flattened['name'] == 'car'
    E       KeyError: 'name'
    
    tests/jsonpickle_test.py:1659: KeyError
    ______________ AdvancedObjectsTestCase.test_base_object_roundrip _______________
    
    self = <object_test.AdvancedObjectsTestCase testMethod=test_base_object_roundrip>
    
        def test_base_object_roundrip(self):
            roundtrip = self.unpickler.restore(self.pickler.flatten(object()))
    >       self.assertEqual(type(roundtrip), object)
    E       AssertionError: <class 'NoneType'> != <class 'object'>
    
    tests/object_test.py:494: AssertionError
    __________________ AdvancedObjectsTestCase.test_dictsubclass ___________________
    
    self = <object_test.AdvancedObjectsTestCase testMethod=test_dictsubclass>
    
        def test_dictsubclass(self):
            obj = DictSubclass()
            obj['key1'] = 1
        
            expect = {
                tags.OBJECT: 'object_test.DictSubclass',
                'key1': 1,
                '__dict__': {},
            }
            flattened = self.pickler.flatten(obj)
    >       self.assertEqual(expect, flattened)
    E       AssertionError: {'py/object': 'object_test.DictSubclass', 'key1': 1, '__dict__': {}} != {'py/object': 'object_test.DictSubclass', 'py/state': None}
    E       - {'__dict__': {}, 'key1': 1, 'py/object': 'object_test.DictSubclass'}
    E       + {'py/object': 'object_test.DictSubclass', 'py/state': None}
    
    tests/object_test.py:367: AssertionError
    ___________ AdvancedObjectsTestCase.test_dictsubclass_notunpickable ____________
    
    self = <object_test.AdvancedObjectsTestCase testMethod=test_dictsubclass_notunpickable>
    
        def test_dictsubclass_notunpickable(self):
            self.pickler.unpicklable = False
        
            obj = DictSubclass()
            obj['key1'] = 1
        
            flattened = self.pickler.flatten(obj)
    >       self.assertEqual(1, flattened['key1'])
    E       TypeError: 'NoneType' object is not subscriptable
    
    tests/object_test.py:381: TypeError
    __________________ AdvancedObjectsTestCase.test_list_subclass __________________
    
    self = <object_test.AdvancedObjectsTestCase testMethod=test_list_subclass>
    
        def test_list_subclass(self):
            obj = ListSubclass()
            obj.extend([1, 2, 3])
            flattened = self.pickler.flatten(obj)
            self.assertTrue(tags.OBJECT in flattened)
    >       self.assertTrue(tags.SEQ in flattened)
    E       AssertionError: False is not true
    
    tests/object_test.py:293: AssertionError
    _____________ AdvancedObjectsTestCase.test_list_subclass_with_data _____________
    
    self = <object_test.AdvancedObjectsTestCase testMethod=test_list_subclass_with_data>
    
        def test_list_subclass_with_data(self):
            obj = ListSubclass()
            obj.extend([1, 2, 3])
            data = SetSubclass([1, 2, 3])
            obj.data = data
            flattened = self.pickler.flatten(obj)
            restored = self.unpickler.restore(flattened)
    >       self.assertEqual(restored, obj)
    E       AssertionError: [] != [1, 2, 3]
    
    tests/object_test.py:315: AssertionError
    __________________ AdvancedObjectsTestCase.test_oldstyleclass __________________
    
    self = <object_test.AdvancedObjectsTestCase testMethod=test_oldstyleclass>
    
        def test_oldstyleclass(self):
            obj = OldStyleClass()
            obj.value = 1234
        
            flattened = self.pickler.flatten(obj)
    >       self.assertEqual(1234, flattened['value'])
    E       KeyError: 'value'
    
    tests/object_test.py:352: KeyError
    __________________ AdvancedObjectsTestCase.test_set_subclass ___________________
    
    self = <object_test.AdvancedObjectsTestCase testMethod=test_set_subclass>
    
        def test_set_subclass(self):
            obj = SetSubclass([1, 2, 3])
            flattened = self.pickler.flatten(obj)
            self.assertTrue(tags.OBJECT in flattened)
    >       self.assertTrue(tags.SEQ in flattened)
    E       AssertionError: False is not true
    
    tests/object_test.py:323: AssertionError
    _____________ AdvancedObjectsTestCase.test_set_subclass_with_data ______________
    
    self = <object_test.AdvancedObjectsTestCase testMethod=test_set_subclass_with_data>
    
        def test_set_subclass_with_data(self):
            obj = SetSubclass([1, 2, 3])
            data = ListSubclass()
            data.extend([1, 2, 3])
            obj.data = data
            flattened = self.pickler.flatten(obj)
            restored = self.unpickler.restore(flattened)
    >       self.assertEqual(restored.data.__class__, ListSubclass)
    E       AssertionError: <class 'NoneType'> != <class 'object_test.ListSubclass'>
    
    tests/object_test.py:338: AssertionError
    __________________________ test_defaultdict_roundtrip __________________________
    
        def test_defaultdict_roundtrip():
            """Make sure we can handle collections.defaultdict(list)"""
            # setup
            defaultdict = collections.defaultdict
            defdict = defaultdict(list)
            defdict['a'] = 1
            defdict['b'].append(2)
            defdict['c'] = defaultdict(dict)
            # jsonpickle work your magic
            encoded = jsonpickle.encode(defdict)
            newdefdict = jsonpickle.decode(encoded)
            # jsonpickle never fails
    >       assert newdefdict['a'] == 1
    E       TypeError: 'NoneType' object is not subscriptable
    
    tests/object_test.py:630: TypeError
    ___________________ test_defaultdict_roundtrip_simple_lambda ___________________
    
        def test_defaultdict_roundtrip_simple_lambda():
            """Make sure we can handle defaultdict(lambda: defaultdict(int))"""
            # setup a sparse collections.defaultdict with simple lambdas
            defaultdict = collections.defaultdict
            defdict = defaultdict(lambda: defaultdict(int))
            defdict[0] = 'zero'
            defdict[1] = defaultdict(lambda: defaultdict(dict))
            defdict[1][0] = 'zero'
            # roundtrip
            encoded = jsonpickle.encode(defdict, keys=True)
            newdefdict = jsonpickle.decode(encoded, keys=True)
    >       assert newdefdict[0] == 'zero'
    E       TypeError: 'NoneType' object is not subscriptable
    
    tests/object_test.py:648: TypeError
    __________________ test_defaultdict_roundtrip_simple_lambda2 ___________________
    
        def test_defaultdict_roundtrip_simple_lambda2():
            """Serialize a defaultdict that contains a lambda"""
            defaultdict = collections.defaultdict
            payload = {'a': defaultdict(lambda: 0)}
            defdict = defaultdict(lambda: 0, payload)
            # roundtrip
            encoded = jsonpickle.encode(defdict, keys=True)
            decoded = jsonpickle.decode(encoded, keys=True)
    >       assert type(decoded) == defaultdict
    E       AssertionError: assert <class 'NoneType'> == <class 'collections.defaultdict'>
    E        +  where <class 'NoneType'> = type(None)
    
    tests/object_test.py:666: AssertionError
    _____________ test_defaultdict_and_things_roundtrip_simple_lambda ______________
    
        def test_defaultdict_and_things_roundtrip_simple_lambda():
            """Serialize a default dict that contains a lambda and objects"""
            thing = Thing('a')
            defaultdict = collections.defaultdict
            defdict = defaultdict(lambda: 0)
            obj = [defdict, thing, thing]
            # roundtrip
            encoded = jsonpickle.encode(obj, keys=True)
            decoded = jsonpickle.decode(encoded, keys=True)
    >       assert decoded[0].default_factory() == 0
    E       AttributeError: 'NoneType' object has no attribute 'default_factory'
    
    tests/object_test.py:679: AttributeError
    ____________ test_defaultdict_subclass_with_self_as_default_factory ____________
    
        def test_defaultdict_subclass_with_self_as_default_factory():
            """Serialize a defaultdict subclass with self as its default factory"""
            cls = ThingWithSelfAsDefaultFactory
            tree = cls()
    >       newtree = _test_defaultdict_tree(tree, cls)
    
    tests/object_test.py:711: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    tree = ThingWithSelfAsDefaultFactory(ThingWithSelfAsDefaultFactory(..., {...}), {'A': ThingWithSelfAsDefaultFactory(ThingWithSelfAsDefaultFactory(..., {...}), {'B': 1, 'C': 2})})
    cls = <class 'object_test.ThingWithSelfAsDefaultFactory'>
    
        def _test_defaultdict_tree(tree, cls):
            tree['A']['B'] = 1
            tree['A']['C'] = 2
            # roundtrip
            encoded = jsonpickle.encode(tree)
            newtree = jsonpickle.decode(encoded)
            # make sure we didn't lose anything
    >       assert type(newtree) == cls
    E       AssertionError: assert <class 'NoneType'> == <class 'object_test.ThingWithSelfAsDefaultFactory'>
    E        +  where <class 'NoneType'> = type(None)
    
    tests/object_test.py:690: AssertionError
    ___________ test_defaultdict_subclass_with_class_as_default_factory ____________
    
        def test_defaultdict_subclass_with_class_as_default_factory():
            """Serialize a defaultdict with a class as its default factory"""
            cls = ThingWithClassAsDefaultFactory
            tree = cls()
    >       newtree = _test_defaultdict_tree(tree, cls)
    
    tests/object_test.py:722: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    tree = ThingWithClassAsDefaultFactory(<class 'object_test.ThingWithClassAsDefaultFactory'>, {'A': ThingWithClassAsDefaultFactory(<class 'object_test.ThingWithClassAsDefaultFactory'>, {'B': 1, 'C': 2})})
    cls = <class 'object_test.ThingWithClassAsDefaultFactory'>
    
        def _test_defaultdict_tree(tree, cls):
            tree['A']['B'] = 1
            tree['A']['C'] = 2
            # roundtrip
            encoded = jsonpickle.encode(tree)
            newtree = jsonpickle.decode(encoded)
            # make sure we didn't lose anything
    >       assert type(newtree) == cls
    E       AssertionError: assert <class 'NoneType'> == <class 'object_test.ThingWithClassAsDefaultFactory'>
    E        +  where <class 'NoneType'> = type(None)
    
    tests/object_test.py:690: AssertionError
    ________________________ test_ordered_dict_unpicklable _________________________
    
        def test_ordered_dict_unpicklable():
            """Serialize an OrderedDict with unpicklable=False"""
            d = collections.OrderedDict([('c', 3), ('a', 1), ('b', 2)])
            encoded = jsonpickle.encode(d, unpicklable=False)
            decoded = jsonpickle.decode(encoded)
    >       assert d == decoded
    E       AssertionError: assert OrderedDict([('c', 3), ('a', 1), ('b', 2)]) == None
    
    tests/object_test.py:785: AssertionError
    ___________________________ test_ordered_dict_nested ___________________________
    
        def test_ordered_dict_nested():
            """Serialize nested dicts with OrderedDict values"""
            bottom = collections.OrderedDict([('z', 1), ('a', 2)])
            middle = collections.OrderedDict([('c', bottom)])
            top = collections.OrderedDict([('b', middle)])
            encoded = jsonpickle.encode(top)
            decoded = jsonpickle.decode(encoded)
            assert top == decoded
            # test unpicklable=False
            encoded = jsonpickle.encode(top, unpicklable=False)
            decoded = jsonpickle.decode(encoded)
    >       assert top == decoded
    E       AssertionError: assert OrderedDict([('b', OrderedDict([('c', OrderedDict([('z', 1), ('a', 2)]))]))]) == None
    
    tests/object_test.py:832: AssertionError
    _________________________ test_newstyleslots_iterable __________________________
    
        def test_newstyleslots_iterable():
            """Seriazlie an object with iterable slots"""
            obj = ThingWithIterableSlots('alpha', 'bravo')
            jsonstr = jsonpickle.encode(obj)
            newobj = jsonpickle.decode(jsonstr)
    >       assert newobj.a == 'alpha'
    E       AttributeError: 'NoneType' object has no attribute 'a'
    
    tests/object_test.py:984: AttributeError
    _______________________ MagicTestCase.test_with_pickling _______________________
    
    self = <wizard_test.MagicTestCase testMethod=test_with_pickling>
    
        def test_with_pickling(self):
            world = World()
            wizard_merlin = Wizard(world, 'Merlin')
            wizard_morgana = Wizard(world, 'Morgana')
            wizard_morgana_prime = Wizard(world, 'Morgana')
        
            self.assertEqual(wizard_morgana.__dict__, wizard_morgana_prime.__dict__)
        
            spell_a = Spell(wizard_merlin, wizard_morgana, 'magic-missile')
            spell_b = Spell(wizard_merlin, wizard_merlin, 'stone-skin')
            spell_c = Spell(wizard_morgana, wizard_merlin, 'geas')
        
            self.assertEqual(wizard_merlin.spells[wizard_morgana][0], spell_a)
            self.assertEqual(wizard_merlin.spells[wizard_merlin][0], spell_b)
            self.assertEqual(wizard_morgana.spells[wizard_merlin][0], spell_c)
            flat_world = encode(world, keys=True)
    >       u_world = decode(flat_world, keys=True)
    
    tests/wizard_test.py:162: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    jsonpickle/unpickler.py:88: in decode
        return context.restore(data, reset=reset, classes=classes)
    jsonpickle/unpickler.py:362: in restore
        value = self._restore(obj)
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:771: in _restore_object
        return self._restore_object_instance(obj, cls, class_name)
    jsonpickle/unpickler.py:747: in _restore_object_instance
        instance = self._restore_object_instance_variables(obj, instance)
    jsonpickle/unpickler.py:693: in _restore_object_instance_variables
        instance = self._restore_state(obj, instance)
    jsonpickle/unpickler.py:652: in _restore_state
        state = self._restore(obj[tags.STATE])
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:798: in _restore_dict
        data[k] = self._restore(v)
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:431: in _restore_list
        children = [self._restore(v) for v in obj]
    jsonpickle/unpickler.py:431: in <listcomp>
        children = [self._restore(v) for v in obj]
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:771: in _restore_object
        return self._restore_object_instance(obj, cls, class_name)
    jsonpickle/unpickler.py:747: in _restore_object_instance
        instance = self._restore_object_instance_variables(obj, instance)
    jsonpickle/unpickler.py:693: in _restore_object_instance_variables
        instance = self._restore_state(obj, instance)
    jsonpickle/unpickler.py:652: in _restore_state
        state = self._restore(obj[tags.STATE])
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:798: in _restore_dict
        data[k] = self._restore(v)
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:464: in _restore_reduce
        reduce_val = list(map(self._restore, obj[tags.REDUCE]))
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:828: in _restore_tuple
        return tuple([self._restore(v) for v in obj[tags.TUPLE]])
    jsonpickle/unpickler.py:828: in <listcomp>
        return tuple([self._restore(v) for v in obj[tags.TUPLE]])
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:828: in _restore_tuple
        return tuple([self._restore(v) for v in obj[tags.TUPLE]])
    jsonpickle/unpickler.py:828: in <listcomp>
        return tuple([self._restore(v) for v in obj[tags.TUPLE]])
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:771: in _restore_object
        return self._restore_object_instance(obj, cls, class_name)
    jsonpickle/unpickler.py:747: in _restore_object_instance
        instance = self._restore_object_instance_variables(obj, instance)
    jsonpickle/unpickler.py:693: in _restore_object_instance_variables
        instance = self._restore_state(obj, instance)
    jsonpickle/unpickler.py:652: in _restore_state
        state = self._restore(obj[tags.STATE])
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:798: in _restore_dict
        data[k] = self._restore(v)
    jsonpickle/unpickler.py:344: in _restore
        return restore(obj)
    jsonpickle/unpickler.py:513: in _restore_reduce
        stage1.__setitem__(k, v)
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    self = <wizard_test.Wizard object at 0x7f269439bb90>
    
        def __hash__(self):
    >       return hash('Wizard %s' % self.name)
    E       AttributeError: 'Wizard' object has no attribute 'name'
    
    tests/wizard_test.py:52: AttributeError
    
    ----------- coverage: platform linux, python 3.11.0-beta-3 -----------
    ...
    
    =========================== short test summary info ============================
    FAILED tests/collections_test.py::test_dict_no_cycle - AttributeError: 'NoneT...
    FAILED tests/collections_test.py::test_dict_self_cycle - KeyError: C(42)
    FAILED tests/collections_test.py::test_dict_mutual_cycle - AttributeError: 'N...
    FAILED tests/collections_test.py::test_set_self_cycle - assert D(42) in {D(42...
    FAILED tests/collections_test.py::test_set_mutual_cycle - assert D(42) in {D(...
    FAILED tests/document_test.py::DocumentTestCase::test_cyclical - AttributeErr...
    FAILED tests/jsonpickle_test.py::PicklingTestCase::test_class - KeyError: 'name'
    FAILED tests/jsonpickle_test.py::PicklingTestCase::test_class_reference - Key...
    FAILED tests/jsonpickle_test.py::PicklingTestCase::test_classdict - KeyError:...
    FAILED tests/jsonpickle_test.py::PicklingTestCase::test_classlist - KeyError:...
    FAILED tests/jsonpickle_test.py::PicklingTestCase::test_type_reference - KeyE...
    FAILED tests/jsonpickle_test.py::PicklingTestCase::test_unpickler_on_missing
    FAILED tests/jsonpickle_test.py::JSONPickleTestCase::test_dict_subclass - Ass...
    FAILED tests/jsonpickle_test.py::JSONPickleTestCase::test_reference_to_list
    FAILED tests/jsonpickle_test.py::JSONPickleTestCase::test_refs_recursive - Ty...
    FAILED tests/jsonpickle_test.py::PicklingProtocol2TestCase::test_reduce_state_dict
    FAILED tests/jsonpickle_test.py::PicklingProtocol2TestCase::test_reduce_state_no_dict
    FAILED tests/jsonpickle_test.py::test_repeat_objects_are_expanded - KeyError:...
    FAILED tests/object_test.py::AdvancedObjectsTestCase::test_base_object_roundrip
    FAILED tests/object_test.py::AdvancedObjectsTestCase::test_dictsubclass - Ass...
    FAILED tests/object_test.py::AdvancedObjectsTestCase::test_dictsubclass_notunpickable
    FAILED tests/object_test.py::AdvancedObjectsTestCase::test_list_subclass - As...
    FAILED tests/object_test.py::AdvancedObjectsTestCase::test_list_subclass_with_data
    FAILED tests/object_test.py::AdvancedObjectsTestCase::test_oldstyleclass - Ke...
    FAILED tests/object_test.py::AdvancedObjectsTestCase::test_set_subclass - Ass...
    FAILED tests/object_test.py::AdvancedObjectsTestCase::test_set_subclass_with_data
    FAILED tests/object_test.py::test_defaultdict_roundtrip - TypeError: 'NoneTyp...
    FAILED tests/object_test.py::test_defaultdict_roundtrip_simple_lambda - TypeE...
    FAILED tests/object_test.py::test_defaultdict_roundtrip_simple_lambda2 - Asse...
    FAILED tests/object_test.py::test_defaultdict_and_things_roundtrip_simple_lambda
    FAILED tests/object_test.py::test_defaultdict_subclass_with_self_as_default_factory
    FAILED tests/object_test.py::test_defaultdict_subclass_with_class_as_default_factory
    FAILED tests/object_test.py::test_ordered_dict_unpicklable - AssertionError: ...
    FAILED tests/object_test.py::test_ordered_dict_nested - AssertionError: asser...
    FAILED tests/object_test.py::test_newstyleslots_iterable - AttributeError: 'N...
    FAILED tests/wizard_test.py::MagicTestCase::test_with_pickling - AttributeErr...
    ERROR ...
    = 36 failed, 214 passed, 45 skipped, 3 deselected, 3 xpassed, 1 error in 4.86s =
    ERROR: InvocationError for command .../jsonpickle/.tox/py311/bin/pytest -k 'not (test_thing_with_module or test_thing_with_submodule)' tests (exited with code 1)
    ___________________________________ summary ____________________________________
    ERROR:   py311: commands failed
    
    compatibility core good-first-issue 
    opened by hroncok 15
  • jsonpickle 2.0.0 fails to decode pickled files created by jsonpickle 1.4.1

    jsonpickle 2.0.0 fails to decode pickled files created by jsonpickle 1.4.1

    I've been attempting to upgrade the jsonpickle package in our project, where we store a number of files in pickled format. It happens that in some UTs for that area their evaluation failed, when I only change the jsonpickle package to 2.0.0. For 1.5.2 it still works. I also locally tested with the real data, in case it would be case of overly specific UTs. But those ended up with corrupted JSON data. As one can see in the screenshotRampdown-pickle-issue, instead of

    "previousFeatureTeam": {
            "py/id": 1
          },
    

    on the left side created with 1.5.2, the version created by jsonpickle suddenly creates a list and effectively doubles the output by reusing existing data (but even that seems corrupted).

    I suspect that the format changed or that maybe 2.0.0 introduced a regression, but I couldn't find any information on what actually changed for 2.0.0. Do I need to do something special for conversions from older data?

    opened by Verequus 15
  • Can't decode pandas dataframes

    Can't decode pandas dataframes

    Pandas DataFrame objects encode without error, but decoding causes a RecursionError.

    import pandas as pd
    import jsonpickle
    import jsonpickle.ext.numpy as jsonpickle_numpy
    jsonpickle_numpy.register_handlers()
    
    df = pd.DataFrame({'foo':[1.3,2.4,3.5,4.6],'bar':[10,20,30,40]})
    s = jsonpickle.encode(df)
    jsonpickle.decode(s)
    

    Produces "... RecursionError: maximum recursion depth exceeded"

    A work-around-- convert dataframe to csv string before encoding

    from io import StringIO
    s = jsonpickle.encode(df.to_csv(index=False))
    pd.read_csv(StringIO(jsonpickle.decode(s)))
    

    Reproduces the encoded DataFrame

    opened by rfdougherty 13
  • Add ability to decode an object from a dict/json string based on provided class

    Add ability to decode an object from a dict/json string based on provided class

    Would be nice to have some functionality that allows object recreation based on provided class. For example:

    class Thing(object):
        def __init__(self, name):
            self.name = name
    
    obj = Thing('Awesome')
    import jsonpickle
    oneway = jsonpickle.encode(obj, unpicklable=False)
    result = jsonpickle.decode(oneway, Thing) # or Thing.__class__
    assert obj.name == result.name
    
    opened by nyxcalamity 13
  • Dict keys

    Dict keys

    Have a big trouble with dict keys. Now, only unicode-string keys supported (int keys converts to unicode string and remains unicode string after decode). So, dict's after encode/decode change the type of keys. That erroneously in much applications.

    wishlist bug 
    opened by FoxKeys 13
  • jsonpickle.decode gives

    jsonpickle.decode gives "AttributeError: readonly attribute"

    I am a new user of jsonpickle. I'm using it to save data from simulation runs so that I can go back and do more data analysis later. I'm encoding is a list of objects (sat_list) of a complex class that includes lists, other objects, and simple data types. Here is the code where I am saving the data:

    import json
    import jsonpickle
    sat_list_JSON = jsonpickle.encode(sat_list, unpicklable=True)
    file = open("output_sat_list_1.json", "w")
    json.dump(sat_list_JSON, file)
    file.close()
    
    

    The code to restore is similarly simple:

    import json
    import jsonpickle
    file = open("output_sat_list_1.json", "r")
    sat_list_JSON = json.load(file)
    file.close()
    sat_list = jsonpickle.decode(sat_list_JSON)
    

    Another list of different objects works but this one gives me an error when I try to decode it:


    AttributeError Traceback (most recent call last) C:\Users\TROCKW~1\AppData\Local\Temp/ipykernel_19136/594918999.py in 444 sat_list_JSON = json.load(file) 445 file.close() --> 446 sat_list = jsonpickle.decode(sat_list_JSON) 447 448 # Figure out how well we did

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in decode(string, backend, context, keys, reset, safe, classes) 48 context = context or Unpickler(keys=keys, backend=backend, safe=safe) 49 data = backend.decode(string) ---> 50 return context.restore(data, reset=reset, classes=classes) 51 52

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in restore(self, obj, reset, classes) 161 if classes: 162 self.register_classes(classes) --> 163 value = self._restore(obj) 164 if reset: 165 self._swap_proxies()

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore(self, obj) 194 else: 195 restore = self._restore_tags(obj) --> 196 return restore(obj) 197 198 def _restore_tags(self, obj):

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore_list(self, obj) 523 parent = [] 524 self._mkref(parent) --> 525 children = [self._restore(v) for v in obj] 526 parent.extend(children) 527 method = _obj_setvalue

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in (.0) 523 parent = [] 524 self._mkref(parent) --> 525 children = [self._restore(v) for v in obj] 526 parent.extend(children) 527 method = _obj_setvalue

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore(self, obj) 194 else: 195 restore = self._restore_tags(obj) --> 196 return restore(obj) 197 198 def _restore_tags(self, obj):

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore_object(self, obj) 357 return self._mkref(obj) 358 --> 359 return self._restore_object_instance(obj, cls) 360 361 def _restore_function(self, obj):

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore_object_instance(self, obj, cls) 419 return instance 420 --> 421 instance = self._restore_object_instance_variables(obj, instance) 422 423 if _safe_hasattr(instance, 'default_factory') and isinstance(

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore_object_instance_variables(self, obj, instance) 475 476 def _restore_object_instance_variables(self, obj, instance): --> 477 instance = self._restore_from_dict(obj, instance) 478 479 # Handle list and set subclasses

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore_from_dict(self, obj, instance, ignorereserved) 444 k = restore_key(k) 445 # step into the namespace --> 446 value = self._restore(v) 447 if util.is_noncomplex(instance) or util.is_dictionary_subclass(instance): 448 try:

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore(self, obj) 194 else: 195 restore = self._restore_tags(obj) --> 196 return restore(obj) 197 198 def _restore_tags(self, obj):

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore_object(self, obj) 357 return self._mkref(obj) 358 --> 359 return self._restore_object_instance(obj, cls) 360 361 def _restore_function(self, obj):

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore_object_instance(self, obj, cls) 419 return instance 420 --> 421 instance = self._restore_object_instance_variables(obj, instance) 422 423 if _safe_hasattr(instance, 'default_factory') and isinstance(

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore_object_instance_variables(self, obj, instance) 475 476 def _restore_object_instance_variables(self, obj, instance): --> 477 instance = self._restore_from_dict(obj, instance) 478 479 # Handle list and set subclasses

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore_from_dict(self, obj, instance, ignorereserved) 444 k = restore_key(k) 445 # step into the namespace --> 446 value = self._restore(v) 447 if util.is_noncomplex(instance) or util.is_dictionary_subclass(instance): 448 try:

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore(self, obj) 194 else: 195 restore = self._restore_tags(obj) --> 196 return restore(obj) 197 198 def _restore_tags(self, obj):

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore_object(self, obj) 357 return self._mkref(obj) 358 --> 359 return self._restore_object_instance(obj, cls) 360 361 def _restore_function(self, obj):

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore_object_instance(self, obj, cls) 419 return instance 420 --> 421 instance = self._restore_object_instance_variables(obj, instance) 422 423 if _safe_hasattr(instance, 'default_factory') and isinstance(

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore_object_instance_variables(self, obj, instance) 475 476 def _restore_object_instance_variables(self, obj, instance): --> 477 instance = self._restore_from_dict(obj, instance) 478 479 # Handle list and set subclasses

    ~\Anaconda3\lib\site-packages\jsonpickle\unpickler.py in _restore_from_dict(self, obj, instance, ignorereserved) 458 continue 459 else: --> 460 setattr(instance, k, value) 461 462 # This instance has an instance variable named k that is

    AttributeError: readonly attribute

    Here is the class definition:

    class satellite:
        'Base class for satellites'
        TLE = None   # Another class
        sat_type = None
        SGP4_sat = None   # Another class
        beam_list = None   # List of another class
        plot_points = None
        connect_points = None
        color = None
        history = None
        sat_num = None
        num_beams = None
        bandwidth_per_beam = None
        beam_sizes = None
        beam_arrangement = None
        orbit_type = None
        
        def __init__(self, TLE, sat_type, sat_num):
            self.TLE = TLE
            self.sat_num = sat_num
            self.sat_type = sat_type;
            self.SGP4_sat = EarthSatellite(TLE[0], TLE[1])
            start_time = ts.from_datetime(self.SGP4_sat.epoch.utc_datetime())
            self.geocentric = self.SGP4_sat.at(start_time)
            self.latitude, self.longitude, self.elevation = self.geocentric.frame_latlon(itrs)
            self.location = (self.latitude.degrees, self.longitude.degrees)
            self.beam_list = []
            self.num_beams = satellite_number_of_beams[self.sat_type]
            self.beam_size = satellite_beam_size[self.sat_type]
            self.bandwidth_per_beam = satellite_bandwidth_per_beam[self.sat_type]
            self.beam_arrangement = satellite_beam_arrangement[sat_type]
            self.steer_extent = satellite_steer_extent[sat_type]
            self.connect_points = []
            self.color = satellite_unit_color[sat_type]
        
        def init_comms(self):
            beam_num = 0
            for band in comm_band_list:
                for b in range(self.num_beams[band]):
                    if self.beam_arrangement == "steerable":
                        self.beam_list.append(Beam(beam_num, self, band, self.location, self.beam_size[band], self.bandwidth_per_beam[band]))
                    else:
                        self.beam_list.append(Beam(beam_num, self, band, beam_locs[beam_num], self.beam_size[band], self.bandwidth_per_beam[band]))
                    beam_num += 1
    
            
        def update_location(self, current_time):
            self.geocentric = self.SGP4_sat.at(current_time)
            self.latitude, self.longitude, self.elevation = self.geocentric.frame_latlon(itrs)
            self.location = (self.latitude.degrees, self.longitude.degrees)
            
            for band in comm_band_list:
                for beam in self.beam_list:
                    if beam.is_connected:
                        if distance.distance(beam.location, self.location) > self.steer_extent:    # old steer location is unreachable
                            beam.location = self.location
                    else:  # if this beam isn't connected, drag it along with the satellite
                        beam.location = self.location
        
    

    Any help is appreciated.

    opened by troyrock 11
  • `jsonpickle` raises exception with `load_backend`

    `jsonpickle` raises exception with `load_backend`

    After updating to the latest version of jsonpickle (I don't know which version I used before), after calling jsonpickle.load_backend with a custom backend, I get this error (on encode):

      File ".../lib/python3.9/site-packages/jsonpickle/pickler.py", line 143, in encode
        context.flatten(value, reset=reset), indent=indent, separators=separators
      File ".../lib/python3.9/site-packages/jsonpickle/pickler.py", line 333, in flatten
        if self._determine_sort_keys():
      File ".../lib/python3.9/site-packages/jsonpickle/pickler.py", line 223, in _determine_sort_keys
        for _, options in self.backend._encoder_options.values():
    AttributeError: module 'dmproject.utils.dmproject_json_pickler' has no attribute '_encoder_options'
    
    documentation not-a-bug 
    opened by erezinman 4
  • 3.0.0: One test fails: AttributeError: module 'jsonpickle.ext' has no attribute 'gmpy'

    3.0.0: One test fails: AttributeError: module 'jsonpickle.ext' has no attribute 'gmpy'

    =========================================================================================== ERRORS ===========================================================================================
    _______________________________________________________________________ ERROR at setup of EcdsaTestCase.test_roundtrip _______________________________________________________________________
    
        @pytest.fixture(scope='module', autouse=True)
        def gmpy_extension():
            """Initialize the gmpy extension for this test module"""
    >       jsonpickle.ext.gmpy.register_handlers()
    E       AttributeError: module 'jsonpickle.ext' has no attribute 'gmpy'
    
    tests/ecdsa_test.py:15: AttributeError
    ====================================================================================== warnings summary ======================================================================================
    ../../../../../../usr/local/lib/python3.9/site-packages/_pytest/config/__init__.py:1294
      /usr/local/lib/python3.9/site-packages/_pytest/config/__init__.py:1294: PytestConfigWarning: Unknown config option: flake8-max-line-length
      
        self._warn_or_fail_if_strict(f"Unknown config option: {key}\n")
    
    ../../../../../../usr/local/lib/python3.9/site-packages/pytest_freezegun.py:17: 634 warnings
      /usr/local/lib/python3.9/site-packages/pytest_freezegun.py:17: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
        if LooseVersion(pytest.__version__) < LooseVersion('3.6.0'):
    
    tests/numpy_test.py::test_ndarray_roundtrip
      /disk-samsung/freebsd-ports/devel/py-jsonpickle/work-py39/jsonpickle-3.0.0/jsonpickle/ext/numpy.py:307: UserWarning: ndarray is defined by reference to an object we do not know how to serialize. A deep copy is serialized instead, breaking memory aliasing.
        warnings.warn(msg)
    
    -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
    ================================================================================== short test summary info ===================================================================================
    SKIPPED [1] tests/sklearn_test.py:9: sklearn is not available
    SKIPPED [1] tests/feedparser_test.py:85: feedparser module not available, please install
    SKIPPED [1] tests/sqlalchemy_test.py:90: sqlalchemy is not installed
    SKIPPED [1] tests/sqlalchemy_test.py:42: sqlalchemy is not installed
    SKIPPED [1] tests/sqlalchemy_test.py:66: sqlalchemy is not installed
    SKIPPED [1] tests/bson_test.py:32: bson is not installed
    SKIPPED [1] tests/bson_test.py:48: bson is not installed
    SKIPPED [1] tests/bson_test.py:73: bson is not installed
    SKIPPED [1] tests/bson_test.py:64: bson is not installed
    SKIPPED [1] tests/bson_test.py:56: bson is not installed
    SKIPPED [1] tests/bson_test.py:40: bson is not installed
    SKIPPED [1] tests/backend_test.py:76: ujson not available; please install
    SKIPPED [1] tests/backend_test.py:68: ujson not available; please install
    SKIPPED [1] tests/backend_test.py:180: ujson not available; please install
    SKIPPED [1] tests/backend_test.py:115: simplejson not available; please install
    SKIPPED [1] tests/backend_test.py:145: simplejson not available; please install
    SKIPPED [1] tests/backend_test.py:76: simplejson not available; please install
    SKIPPED [1] tests/backend_test.py:105: simplejson not available; please install
    SKIPPED [1] tests/backend_test.py:68: simplejson not available; please install
    SKIPPED [1] tests/backend_test.py:68: yajl not available; please install
    SKIPPED [1] tests/backend_test.py:76: yajl not available; please install
    SKIPPED [1] tests/backend_test.py:166: yajl not available; please install
    ============================================================= 292 passed, 22 skipped, 3 xpassed, 636 warnings, 1 error in 3.49s ==============================================================
    *** Error code 1
    

    python-3.9 FreeBSD 13.1

    bug cannot-reproduce 
    opened by yurivict 5
  • Hotfix jack son style

    Hotfix jack son style

    Hotfix with solution for #412

    (I apologize in advance I was not able to run the tests, any help on the error will be much appreciated - when installing numpy in the virtual environment I got: AttibuteError: fcompiler)

    opened by AZblo 3
  • Include py/id attribute in all object declaration to identify univocally each object in a JSON file

    Include py/id attribute in all object declaration to identify univocally each object in a JSON file

    We would like to add the py/id attribute next to all objects in the JSON file.

    • In the current implementation no py/id is given to the first instance of an object in the py/id. When encoding/decoding, each new object is given an ID based in their order of appeareance in the json file.
    • While this implementation is perfectly fine for encoding/decoding using jsonpickle; in order to have a more generic implementation, compatible with libraries in other programming languages it is proposed to make appear explicitly the py/id of the first instance of an object in the JSON file.

    Current implementation { "py/obj": "javaTypes.SystemComponent", "block": { "py/obj": "javaTypes.Block", "id": 25, "port": { "py/obj": "javaTypes.Port", "id": 35, "name": "puerto2" }, "link": { "py/obj": "javaTypes.Link", "id": 45, "port": {"py/id": 17002} } }, "link": { "py/id": 3 }, "port": { "py/id": 2 } }

    Desired implementation (note the new attribute py/id appearing next to each py/obj declaration) { "py/obj": "javaTypes.SystemComponent", "py/id": 0, "block": { "py/obj": "javaTypes.Block", "py/id": 1, "id": 25, "port": { "py/obj": "javaTypes.Port", "py/id": 2, "id": 35, "name": "puerto2" }, "link": { "py/obj": "javaTypes.Link", "py/id": 3, "id": 45, "port": {"py/id": 17002} } }, "link": { "py/id": 3 }, "port": { "py/id": 2 } }

    ** Advantages **

    • Format compatible to Java JackSON library, very useful for exchanging JSON file between Java and Python modules, creating the same object in both ends.
    • Possibility to parse the JSON file unambiguosly, indepently from the order of appeareance of the new object instances.
    core enhancement 
    opened by AZblo 4
  • Would be nice to have YAML pickle

    Would be nice to have YAML pickle

    YAML has multiple features that make it a better choice for pickling and serialization:

    Tags. You could reliably represent/mark special objects using the tag metadata instead of praying that the original data does not have keys like "tag/id".

    Object references. You could represent object cycles natively.

    Non-string keys. YAML supports anything as a map key (list, dict etc).

    wishlist enhancement not-a-bug 
    opened by Ark-kun 1
  • pandas dataframe with list as values

    pandas dataframe with list as values

    Consider this code:

    import jsonpickle
    import jsonpickle.ext.numpy as jsonpickle_numpy
    import jsonpickle.ext.pandas as jsonpickle_pandas
    import pandas as pd
    
    jsonpickle_pandas.register_handlers()
    jsonpickle_numpy.register_handlers()
    
    
    a = pd.DataFrame({"date": [["20220921"]]})
    b = jsonpickle.decode(jsonpickle.encode(df, keys=True))
    

    if you run this, you get:

    $ py -i foo.py 
    >>> a['date'][0]
    ['20220921']
    >>> b['date'][0]
    "['20220921']"
    

    i.e. a list[str] has been changed to a str

    Is there any way to avoid this?

    bug good-first-issue 
    opened by feizerl 7
Crappy tool to convert .scw files to .json and and vice versa.

SCW-JSON-TOOL Crappy tool to convert .scw files to .json and vice versa. How to use Run main.py file with two arguments: python main.py <scw2json or j

Fred31 5 May 14, 2021
Ultra fast JSON decoder and encoder written in C with Python bindings

UltraJSON UltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for Python 3.6+. Install with pip: $ python -m pip insta

null 3.9k Jan 2, 2023
simplejson is a simple, fast, extensible JSON encoder/decoder for Python

simplejson simplejson is a simple, fast, complete, correct and extensible JSON <http://json.org> encoder and decoder for Python 3.3+ with legacy suppo

null 1.5k Dec 31, 2022
🦉 Modern high-performance serialization utilities for Python (JSON, MessagePack, Pickle)

srsly: Modern high-performance serialization utilities for Python This package bundles some of the best Python serialization libraries into one standa

Explosion 329 Dec 28, 2022
A lightweight library for converting complex objects to and from simple Python datatypes.

marshmallow: simplified object serialization marshmallow is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, t

marshmallow-code 6.4k Jan 2, 2023
Generic ASN.1 library for Python

ASN.1 library for Python This is a free and open source implementation of ASN.1 types and codecs as a Python package. It has been first written to sup

Ilya Etingof 223 Dec 11, 2022
FlatBuffers: Memory Efficient Serialization Library

FlatBuffers FlatBuffers is a cross platform serialization library architected for maximum memory efficiency. It allows you to directly access serializ

Google 19.6k Jan 1, 2023
MessagePack serializer implementation for Python msgpack.org[Python]

MessagePack for Python What's this MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JS

MessagePack 1.7k Dec 29, 2022
Extended pickling support for Python objects

cloudpickle cloudpickle makes it possible to serialize Python constructs not supported by the default pickle module from the Python standard library.

null 1.3k Jan 5, 2023
serialize all of python

dill serialize all of python About Dill dill extends python's pickle module for serializing and de-serializing python objects to the majority of the b

The UQ Foundation 1.8k Jan 7, 2023
Python wrapper around rapidjson

python-rapidjson Python wrapper around RapidJSON Authors: Ken Robbins <[email protected]> Lele Gaifax <[email protected]> License: MIT License Sta

null 469 Jan 4, 2023
Python bindings for the simdjson project.

pysimdjson Python bindings for the simdjson project, a SIMD-accelerated JSON parser. If SIMD instructions are unavailable a fallback parser is used, m

Tyler Kennedy 562 Jan 8, 2023
Turn (almost) any Python command line program into a full GUI application with one line

Gooey Turn (almost) any Python 2 or 3 Console Program into a GUI application with one line Support this project Table of Contents Gooey Table of conte

Chris 17k Jan 9, 2023
Standards-compliant library for parsing and serializing HTML documents and fragments in Python

html5lib html5lib is a pure-python library for parsing HTML. It is designed to conform to the WHATWG HTML specification, as is implemented by all majo

null 1k Dec 27, 2022
An account generator for guilded.gg that I made a while back and decided to bring back up

An account generator for guilded.gg that I made a while back and decided to bring back up

null 8 Nov 17, 2022
Turn any live video stream or locally stored video into a dataset of interesting samples for ML training, or any other type of analysis.

Sieve Video Data Collection Example Find samples that are interesting within hours of raw video, for free and completely automatically using Sieve API

Sieve 72 Aug 1, 2022
A python library to convert arbitrary strings representing business opening hours into a JSON format that's easier to use in code

A python library to convert arbitrary strings representing business opening hours into a JSON format that's easier to use in code

Adrian Edwards 9 Dec 2, 2022
Turn any OpenAPI2/3 and Postman Collection file into an API server with mocking, transformations and validations.

Prism is a set of packages for API mocking and contract testing with OpenAPI v2 (formerly known as Swagger) and OpenAPI v3.x. Mock Servers: Life-like

Stoplight 3.3k Jan 5, 2023