Output widget fails: can't clean datetime for JSON
See original GitHub issueHi,
the Output widget doesn’t appear to work with rich display data:
In the notebook,
from ipywidgets import Output
w = Output()
w.clear_output()
results in
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-c7669a04e60f> in <module>()
1 from ipywidgets import Output
2 w = Output()
----> 3 w.clear_output()
/home/rick/src/ipywidgets/ipywidgets/widgets/widget_output.py in clear_output(self, *pargs, **kwargs)
36 def clear_output(self, *pargs, **kwargs):
37 with self:
---> 38 clear_output(*pargs, **kwargs)
39
40 def __enter__(self):
/home/rick/src/ipython/IPython/core/display.py in clear_output(wait)
900 from IPython.core.interactiveshell import InteractiveShell
901 if InteractiveShell.initialized():
--> 902 InteractiveShell.instance().display_pub.clear_output(wait)
903 else:
904 from IPython.utils import io
/home/rick/src/notebook/src/ipykernel/ipykernel/zmqshell.py in clear_output(self, wait)
92 self.session.send(
93 self.pub_socket, u'clear_output', content,
---> 94 parent=self.parent_header, ident=self.topic,
95 )
96
/home/rick/src/ipywidgets/ipywidgets/widgets/widget_output.py in send_hook(stream, msg_or_type, content, parent, ident, buffers, track, header, metadata)
61 # If this is a message type that we want to forward, forward it.
62 if stream is kernel.iopub_socket and msg_type in ['clear_output', 'stream', 'display_data']:
---> 63 self.send(msg)
64 else:
65 send(stream, msg, ident=ident, buffers=buffers, track=track)
/home/rick/src/ipywidgets/ipywidgets/widgets/widget.py in send(self, content, buffers)
303 Binary buffers to send with message
304 """
--> 305 self._send({"method": "custom", "content": content}, buffers=buffers)
306
307 def on_msg(self, callback, remove=False):
/home/rick/src/ipywidgets/ipywidgets/widgets/widget.py in _send(self, msg, buffers)
454 def _send(self, msg, buffers=None):
455 """Sends a message to the model in the front-end."""
--> 456 self.comm.send(data=msg, buffers=buffers)
457
458
/home/rick/src/notebook/src/ipykernel/ipykernel/comm/comm.py in send(self, data, metadata, buffers)
127 """Send a message to the frontend-side version of this comm"""
128 self._publish_msg('comm_msg',
--> 129 data=data, metadata=metadata, buffers=buffers,
130 )
131
/home/rick/src/notebook/src/ipykernel/ipykernel/comm/comm.py in _publish_msg(self, msg_type, data, metadata, buffers, **keys)
75 with open('/home/rick/foo', 'at') as f:
76 f.write('Sending %s\n\n' % dict(data=data, comm_id=self.comm_id, **keys))
---> 77 content = json_clean(dict(data=data, comm_id=self.comm_id, **keys))
78 self.session.send(self.iopub_socket, msg_type,
79 content,
/home/rick/src/notebook/src/ipykernel/ipykernel/jsonutil.py in json_clean(obj)
161 out = {}
162 for k,v in iteritems(obj):
--> 163 out[unicode_type(k)] = json_clean(v)
164 return out
165
/home/rick/src/notebook/src/ipykernel/ipykernel/jsonutil.py in json_clean(obj)
161 out = {}
162 for k,v in iteritems(obj):
--> 163 out[unicode_type(k)] = json_clean(v)
164 return out
165
/home/rick/src/notebook/src/ipykernel/ipykernel/jsonutil.py in json_clean(obj)
161 out = {}
162 for k,v in iteritems(obj):
--> 163 out[unicode_type(k)] = json_clean(v)
164 return out
165
/home/rick/src/notebook/src/ipykernel/ipykernel/jsonutil.py in json_clean(obj)
161 out = {}
162 for k,v in iteritems(obj):
--> 163 out[unicode_type(k)] = json_clean(v)
164 return out
165
/home/rick/src/notebook/src/ipykernel/ipykernel/jsonutil.py in json_clean(obj)
165
166 # we don't understand it, it's probably an unserializable object
--> 167 raise ValueError("Can't clean for JSON: %r" % obj)
ValueError: Can't clean for JSON: datetime.datetime(2015, 5, 26, 16, 13, 44, 86776)
I can’t tell if more of the message header is being directed down the comm channel than it should be, bringing in the datetime, or of the datetime should have been converted to a string at some point (or some other problem…)
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to overcome "datetime.datetime not JSON serializable"?
My quick & dirty JSON dump that eats dates and everything: json.dumps(my_dictionary, indent=4, sort_keys=True, default=str). default is a function applied ...
Read more >how to reflect a date extracted from json to a script
Dear, I have a problem to extract a string with a date inside a json to reflect it in a date / time...
Read more >TextView - Android Developers
org.json ... android:enabled, Specifies whether the widget is enabled. ... Sets the right-hand compound drawable of the TextView to the "error" icon and ......
Read more >Changelog — Python 3.11.1 documentation
gh-91581: Remove an unhandled error case in the C implementation of calls to datetime.fromtimestamp with no time zone (i.e. getting a local time...
Read more >Bug listing with status UNCONFIRMED as at 2022/12/24 17 ...
status:UNCONFIRMED resolution: severity:normal · Bug:440598 - "font.eclass outputs elog messages that shoud only be displayed for new installs" ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This still doesn’t work when it’s datetime.date(…) instead of datetime.datetime(…)
That works for me now, thanks!