mcs07 / PubChemPy

Python wrapper for the PubChem PUG REST API.
http://pubchempy.readthedocs.io
MIT License
379 stars 106 forks source link

Assay.from_aid().to_dict() fails for multiple AIDs #77

Open watplatt opened 1 year ago

watplatt commented 1 year ago

Assay.from_aid(2016).to_dict() fails. The reason is that a lot of 'comment' entries are absent altogether. The result is access to other records (e.g. 'target') is denied even if they do exist.

I can catch the exception, but it is a false failure (the 'target' may be there, but I can't get to it) for the records I want. Here's the report...

KeyError Traceback (most recent call last) Input In [36], in <cell line: 6>() 3 except Exception as x: 4 print(x) ----> 6 print(Assay.from_aid(2016).to_dict())

File ~/.conda/envs/myfastai/lib/python3.9/site-packages/pubchempy.py:1187, in Assay.to_dict(self, properties) 1185 if not properties: 1186 properties = [p for p in dir(Assay) if isinstance(getattr(Assay, p), property)] -> 1187 return {p: getattr(self, p) for p in properties}

File ~/.conda/envs/myfastai/lib/python3.9/site-packages/pubchempy.py:1187, in (.0) 1185 if not properties: 1186 properties = [p for p in dir(Assay) if isinstance(getattr(Assay, p), property)] -> 1187 return {p: getattr(self, p) for p in properties}

File ~/.conda/envs/myfastai/lib/python3.9/site-packages/pubchempy.py:1217, in Assay.comments(self) 1214 @property 1215 def comments(self): 1216 """Comments and additional information.""" -> 1217 return [comment for comment in self.record['assay']['descr']['comment'] if comment]

KeyError: 'comment'