ipython / ipython/ipykernel

Issues with pythreejs with 6.4.0

Abierto
#771 0 comentarios 4 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
734
Forks
412
Merge medio
1 d 5 h
PR fusionados (30 d)
8

Descripción

Upgrading from `ipykernel==6.3.1` `ipykernel==6.4.0` breaks `pythreejs` when serializing any `pythreejs.OrbitControls`.

```
~/python/pyvista/pyvista/jupyter/pv_pythreejs.py in convert_renderer(pv_renderer)
494 )
495
--> 496 controls = [tjs.OrbitControls(controlling=camera)]
497
498 renderer = tjs.Renderer(camera=camera,

/tmp/venv/lib/python3.8/site-packages/pythreejs/controls/OrbitControls_autogen.py in __init__(self, controlling, **kwargs)
27 def __init__(self, controlling=None, **kwargs):
28 kwargs['controlling'] = controlling
---> 29 super(OrbitControls, self).__init__(**kwargs)
30
31 _model_name = Unicode('OrbitControlsModel').tag(sync=True)

/tmp/venv/lib/python3.8/site-packages/pythreejs/controls/Controls_autogen.py in __init__(self, **kwargs)
28
29 def __init__(self, **kwargs):
---> 30 super(Controls, self).__init__(**kwargs)
31
32 _model_name = Unicode('ControlsModel').tag(sync=True)

/tmp/venv/lib/python3.8/site-packages/pythreejs/_base/Three.py in __init__(self, **kwargs)
15
16 def __init__(self, **kwargs):
---> 17 super(ThreeWidget, self).__init__(**kwargs)
18 self.on_msg(self._on_potential_ret_val)
19

/tmp/venv/lib/python3.8/site-packages/ipywidgets/widgets/widget.py in __init__(self, **kwargs)
413
414 Widget._call_widget_constructed(self)
--> 415 self.open()
416
417 def __del__(self):

/tmp/venv/lib/python3.8/site-packages/ipywidgets/widgets/widget.py in open(self)
436 args['comm_id'] = self._model_id
437
--> 438 self.comm = Comm(**args)
439
440 @observe('comm')

/tmp/venv/lib/python3.8/site-packages/ipykernel/comm/comm.py in __init__(self, target_name, data, metadata, buffers, **kwargs)
55 if self.primary:
56 # I am primary, open my peer.
---> 57 self.open(data=data, metadata=metadata, buffers=buffers)
58 else:
59 self._closed = False

/tmp/venv/lib/python3.8/site-packages/ipykernel/comm/comm.py in open(self, data, metadata, buffers)
89 comm_manager.register_comm(self)
90 try:
---> 91 self._publish_msg('comm_open',
92 data=data, metadata=metadata, buffers=buffers,
93 target_name=self.target_name,

/tmp/venv/lib/python3.8/site-packages/ipykernel/comm/comm.py in _publish_msg(self, msg_type, data, metadata, buffers, **keys)
64 metadata = {} if metadata is None else metadata
65 content = json_clean(dict(data=data, comm_id=self.comm_id, **keys))
---> 66 self.kernel.session.send(self.kernel.iopub_socket, msg_type,
67 content,
68 metadata=json_clean(metadata),

/tmp/venv/lib/python3.8/site-packages/jupyter_client/session.py in send(self, stream, msg_or_type, content, parent, ident, buffers, track, header, metadata)
828 if self.adapt_version:
829 msg = adapt(msg, self.adapt_version)
--> 830 to_send = self.serialize(msg, ident)
831 to_send.extend(buffers)
832 longest = max([len(s) for s in to_send])

/tmp/venv/lib/python3.8/site-packages/jupyter_client/session.py in serialize(self, msg, ident)
702 content = self.none
703 elif isinstance(content, dict):
--> 704 content = self.pack(content)
705 elif isinstance(content, bytes):
706 # content is already packed, as in a relayed message

/tmp/venv/lib/python3.8/site-packages/jupyter_client/session.py in json_packer(obj)
93
94 def json_packer(obj):
---> 95 return jsonapi.dumps(
96 obj,
97 default=json_default,

/tmp/venv/lib/python3.8/site-packages/zmq/utils/jsonapi.py in dumps(o, **kwargs)
23 Keyword arguments are passed along to :py:func:`json.dumps`.
24 """
---> 25 return json.dumps(o, **kwargs).encode("utf8")
26
27

/usr/lib/python3.8/json/__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
232 if cls is None:
233 cls = JSONEncoder
--> 234 return cls(
235 skipkeys=skipkeys, ensure_ascii=ensure_ascii,
236 check_circular=check_circular, allow_nan=allow_nan, indent=indent,

/usr/lib/python3.8/json/encoder.py in encode(self, o)
197 # exceptions aren't as detailed. The list call should be roughly
198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
201 chunks = list(chunks)

/usr/lib/python3.8/json/encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,

ValueError: Out of range float values are not JSON compliant
```

Reason being is the `inf` in the orbit controls that was fine before the last update:
```
{'state': {'_model_module': 'jupyter-threejs', '_model_module_version': '^2.1.0', '_model_name': 'OrbitControlsModel', '_view_count': None, '_view_module': None, '_view_module_version': '', '_view_name': None, 'autoRotate': False, 'autoRotateSpeed': 2.0, 'controlling': 'IPY_MODEL_a205842466d44cf0a9bcd908a9c54253', 'dampingFactor': 0.25, 'enableDamping': False, 'enableKeys': True, 'enablePan': True, 'enableRotate': True, 'enableZoom': True, 'enabled': True, 'keyPanSpeed': 7.0, 'maxAzimuthAngle': inf, 'maxDistance': inf, 'maxPolarAngle': 3.141592653589793, 'maxZoom': inf, 'minAzimuthAngle': -inf, 'minDistance': 0.0, 'minPolarAngle': 0.0, 'minZoom': 0.0, 'panSpeed': 1.0, 'rotateSpeed': 1.0, 'screenSpacePanning': True, 'target': (0.0, 0.0, 0.0), 'zoomSpeed': 1.0}, 'buffer_paths': []}
```

I'm not sure if this something that needs to be fixed in `ipywidgets`, but I'm posting it here so there's a record of this issue.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.