adsabs / adsabs-dev-api

Developer API service description and example client code
162 stars 58 forks source link

Can't use != to check if an article exists in a container #67

Closed shortorian closed 3 years ago

shortorian commented 3 years ago

I'm using the API to get a set of articles and then iterating over a pandas DataFrame containing those articles, searching for references from or citations to articles found in the first round of searches. I'm currently using the string 'x' for cells that do not contain useful data. To run the second set of searches I do

if (dataframe['columnWithArticles'].loc[index] != 'x'):
    #code with SearchQueries

But when the column with articles contains an article this comparison fails with the following error

c:\users\appdata\local\programs\python\python38-32\lib\site-packages\ads\search.py in __ne__(self, other)
     56
     57     def __ne__(self, other):
---> 58         return not self.__eq__(other)
     59
     60     def keys(self):

c:\users\appdata\local\programs\python\python38-32\lib\site-packages\ads\search.py in __eq__(self, other)
     52     def __eq__(self, other):
     53         if self._raw.get("bibcode") is None or other._raw.get("bibcode") is None:
---> 54             raise TypeError("Cannot compare articles without bibcodes")
     55         return self._raw['bibcode'] == other._raw['bibcode']
     56

TypeError: Cannot compare articles without bibcodes

I expected that article objects would be unequal to an object of any other type, but it looks like articles can only handle comparisons to objects with bibcode attributes. Is this a bug or is this expected behavior?

marblestation commented 3 years ago

This looks related to the unofficial ADS python package which we do not maintain. Please, report this issue in their github repository, they will be able to better guide you. Thanks!