ipython / ipykernel

IPython Kernel for Jupyter
https://ipykernel.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
646 stars 367 forks source link

Serialize a dict with non-orderable keys #269

Open Prikers opened 7 years ago

Prikers commented 7 years ago

It seems that it is not possible to serialize a dict which a non-orderable keys:

from ipykernel.serialize import serialize_object
serialize_object({'A': 1, 2: 2})

File "...\ipykernel\serialize.py", line 85, in serialize_object
    for k in sorted(obj):
TypeError: '<' not supported between instances of 'int' and 'str'

Is ordering the keys mandatory to serialize the dict? (sorry if that is a dumb question)

takluyver commented 7 years ago

ipykernel.serialize is marked as deprecated, and the functionality moved to ipyparallel. If Spyder is using ipykernel.serialize, we need to either find an alternative for spider or reconsider the deprecation.

Pinging @minrk

ccordoba12 commented 7 years ago

@takluyver, we know it's deprecated. We are depending on ipykernel for now to not add yet another dependency to Spyder.

However, I think the problem reported by @Prikers is still present in ipyparallel.

minrk commented 7 years ago

Indeed the bug is present in ipyparallel. The ipykernel code is deprecated and destined to be removed, so I'd recommend moving away from it if you can. I would recommend switching to cloudpickle instead of ipykernel.serialize and data_pub for this, which are not part of the Jupyter spec and will be removed from ipykernel at some point.