mcs07 / PubChemPy

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

to_dic bugs on Substance #59

Open HYUNSEONG-KIM opened 3 years ago

HYUNSEONG-KIM commented 3 years ago

Some data in Pubchem does not provides compound value while other data source provides. In this case, to_dataframe or to_dict funtion generate error no "compound"

    """
    Some substances of pubchem data doesnot provide compound key
    for c in self.record['compound']:
        if c['id']['type'] == CompoundIdType.STANDARDIZED:
            return c['id']['id']['cid']

    """
    if 'compound' in self.record:
        for c in self.record['compound']:
            if c['id']['type'] == CompoundIdType.STANDARDIZED:
                return c['id']['id']['cid']

I think it can be fixed with checking whether Substances has a "compound" key in record

example case bug occurres: pcp.get_substances("65983-31-5", "name")

It return almost 21 substance from pubchem server and 20th substance

Substance(342573178) has no "compound" key in record, therefore it generates errors when you use to_dataframe or to_dict