dendrograms / astrodendro

Generate a dendrogram from a dataset
https://dendrograms.readthedocs.io/
Other
37 stars 38 forks source link

Replace eval; deal with inf #134

Open keflavich opened 9 years ago

keflavich commented 9 years ago

I encountered this error:

  File "/Users/adam/repos/astrodendro/astrodendro/io/util.py", line 54, in parse_newick
    items[branch_id] = eval("{%s}" % string[start + 1:end])
  File "<string>", line 1, in <module>
NameError: name 'inf' is not defined

which occurred because my dendrogram was written with boatloads of infs int it. That's a problem with the dendrogram, and maybe it should be handled higher up - there weren't infs in my data originally, but there were nans.

More importantly, though, the use of eval is insecure and unreliable. I replaced it with ast.literal_eval so that only dictionaries containing numbers and None should be returned.

@astrofrog @ChrisBeaumont - Changing inf to None is probably not the right approach, but it's a stopgap. Can you recommend another approach?

keflavich commented 9 years ago

Whoa I lied there were infs! But anyway dendro should deal with those somehow.