Skip to content

get_cids method returns a list of Dict when domain = "substance" #133

Description

@simulkade

Not a bug but the return type of get_cids is list[int]. However, when called with domain = "substance", it returns a list of dictionaries that contains both SID and CID.

import pubchempy as pcp
pcp.get_cids("8000-78-0", namespace="name", domain="substance") # garlic oil

returns

[{'SID': 442031951, 'CID': [6850738]},
 {'SID': 445479966, 'CID': [6850738]},
 {'SID': 446464370, 'CID': [6850738]},
 {'SID': 479884108, 'CID': [6850738]},
 {'SID': 480557704, 'CID': [6850738]},
 {'SID': 481120361, 'CID': [6850738]},
 {'SID': 488195857, 'CID': [6850738]},
 {'SID': 497868770, 'CID': [6850738]},
 {'SID': 503477764, 'CID': [6850738]},
 {'SID': 504051010, 'CID': [6850738]},
 {'SID': 507705895, 'CID': [6850738]},
 {'SID': 135264271},
 {'SID': 176258937},
 {'SID': 349326089},
 {'SID': 363901999},
 {'SID': 441076689},
 {'SID': 472186491},
 {'SID': 472388580},
 {'SID': 477517504},
 {'SID': 482032741},
 {'SID': 485460846},
 {'SID': 486323371},
 {'SID': 488208578},
 {'SID': 496304552}]

What I am doing now is the following, e.g. when looking for a substance with its CASRN (useful when the get_compounds returns an empty list for a given CASRN):

cids = pcp.get_cids(casrn, namespace="name", domain="substance")
cid_list = []
if len(cids)> 0:
    for cid in cids:
        if 'CID' in cid.keys():
            cid_list.append(cid['CID'])
    cid_list = list(set(cid_list))  # Removing duplicates

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions