datajoint-python icon indicating copy to clipboard operation
datajoint-python copied to clipboard

dj.diagram not working after update to 14.1

Open troselab-setup opened this issue 1 year ago • 4 comments

Hi all, has there been a change to dj.Diagram? I updated to dj 14.1 and now I am receiving this error:

`--------------------------------------------------------------------------- ValueError Traceback (most recent call last) File ~/miniconda3/envs/datajoint/lib/python3.8/site-packages/IPython/core/formatters.py:343, in BaseFormatter.call(self, obj) 341 method = get_real_method(obj, self.print_method) 342 if method is not None: --> 343 return method() 344 return None 345 else:

File ~/miniconda3/envs/datajoint/lib/python3.8/site-packages/datajoint/diagram.py:436, in Diagram.repr_svg(self) 435 def repr_svg(self): --> 436 return self.make_svg().repr_svg()

File ~/miniconda3/envs/datajoint/lib/python3.8/site-packages/datajoint/diagram.py:424, in Diagram.make_svg(self) 421 def make_svg(self): 422 from IPython.display import SVG --> 424 return SVG(self.make_dot().create_svg())

File ~/miniconda3/envs/datajoint/lib/python3.8/site-packages/datajoint/diagram.py:371, in Diagram.make_dot(self) 308 label_props = { # http://matplotlib.org/examples/color/named_colors.html 309 None: dict( 310 shape="circle", (...) 364 ), 365 } 366 node_props = { 367 node: label_props[d["node_type"]] 368 for node, d in dict(graph.nodes(data=True)).items() 369 } --> 371 dot = nx.drawing.nx_pydot.to_pydot(graph) 372 for node in dot.get_nodes(): 373 node.set_shape("circle")

File ~/miniconda3/envs/datajoint/lib/python3.8/site-packages/networkx/drawing/nx_pydot.py:309, in to_pydot(N) 298 raise_error = ( 299 _check_colon_quotes(u) 300 or _check_colon_quotes(v) (...) 306 ) 307 ) 308 if raise_error: --> 309 raise ValueError( 310 f'Node names and attributes should not contain ":" unless they are quoted with "".
311 For example the string 'attribute:data1' should be written as '"attribute:data1"'.
312 Please refer https://github.com/pydot/pydot/issues/258' 313 ) 314 edge = pydot.Edge(u, v, **str_edgedata) 315 P.add_edge(edge)

ValueError: Node names and attributes should not contain ":" unless they are quoted with "". For example the string 'attribute:data1' should be written as '"attribute:data1"'. Please refer https://github.com/pydot/pydot/issues/258`

Reproducibility

Include:

  • Linux
  • Python 3.8.16

troselab-setup avatar Jul 18 '23 07:07 troselab-setup

I see this has been raised already here: https://github.com/datajoint/datajoint-python/issues/1065#issue-1444879799

troselab-setup avatar Jul 18 '23 07:07 troselab-setup

I would describe this issue as 'networkx rejects dj.Diagrams with attribute mapping'

Minimal replication
import datajoint as dj

schema = dj.schema("temp_demo")

@schema
class A(dj.Manual):
    definition = """
    a : int
    """

@schema
class B(dj.Manual):
    definition = """
    b : int
    -> A
    """

if __name__ == "__main__":
    (dj.Diagram(B) - 1).draw()
Error stack
🌸 python 3.9.16 🌸
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File ~/wrk/spyglass/temp-demo.py:22
     15     definition = """
     16     b : int
     17     -> A
     18     """
     21 if __name__ == "__main__":
---> 22     (dj.Diagram(B) - 1).draw()

File ~/wrk/datajoint-python/datajoint/diagram.py:440, in Diagram.draw(self)
    438 def draw(self):
    439     if plot_active:
--> 440         plt.imshow(self.make_image())
    441         plt.gca().axis("off")
    442         plt.show()

File ~/wrk/datajoint-python/datajoint/diagram.py:431, in Diagram.make_image(self)
    429 def make_image(self):
    430     if plot_active:
--> 431         return plt.imread(self.make_png())
    432     else:
    433         raise DataJointError("pyplot was not imported")

File ~/wrk/datajoint-python/datajoint/diagram.py:427, in Diagram.make_png(self)
    426 def make_png(self):
--> 427     return io.BytesIO(self.make_dot().create_png())

File ~/wrk/datajoint-python/datajoint/diagram.py:371, in Diagram.make_dot(self)
    308 label_props = {  # http://matplotlib.org/examples/color/named_colors.html
    309     None: dict(
    310         shape="circle",
   (...)
    364     ),
    365 }
    366 node_props = {
    367     node: label_props[d["node_type"]]
    368     for node, d in dict(graph.nodes(data=True)).items()
    369 }
--> 371 dot = nx.drawing.nx_pydot.to_pydot(graph)
    372 for node in dot.get_nodes():
    373     node.set_shape("circle")

File ~/miniconda3/envs/spy/lib/python3.9/site-packages/networkx/drawing/nx_pydot.py:311, in to_pydot(N)
    300 raise_error = (
    301     _check_colon_quotes(u)
    302     or _check_colon_quotes(v)
   (...)
    308     )
    309 )
    310 if raise_error:
--> 311     raise ValueError(
    312         f'Node names and attributes should not contain ":" unless they are quoted with "".\
    313         For example the string \'attribute:data1\' should be written as \'"attribute:data1"\'.\
    314         Please refer https://github.com/pydot/pydot/issues/258'
    315     )
    316 edge = pydot.Edge(u, v, **str_edgedata)
    317 P.add_edge(edge)

ValueError: Node names and attributes should not contain ":" unless they are quoted with "".                    For example the string 'attribute:data1' should be written as '"attribute:data1"'.                    Please refer https://github.com/pydot/pydot/issues/258

CBroz1 avatar Mar 25 '24 19:03 CBroz1

Hi! Is there an update to this?

trose-neuro avatar Jun 03 '24 13:06 trose-neuro

fixing this week :-)

dimitri-yatsenko avatar Jun 03 '24 13:06 dimitri-yatsenko