iobis / pyobis

OBIS Python client
https://iobis.github.io/pyobis
MIT License
14 stars 10 forks source link

Search by instituteid does not work #121

Closed MathewBiddle closed 1 year ago

MathewBiddle commented 1 year ago

I'm working on a project where I'd like to use pyobis to search for all the records associated with a specific institution. Below is an example of the key part of the code that is not functioning as expected.

from pyobis import occurrences

institution_id = '23070'

query = occurrences.getpoints(instituteid = institution_id)

query.api_url

returns:

'https://api.obis.org/v3/occurrence/points?'

When it should return

https://api.obis.org/v3/occurrence/points?instituteid=23070

I'm running

pyobis.__version__
'1.3.0'
ayushanand18 commented 1 year ago

Thank you for highlighting this. This does not work because instituteid isn't a default argument in the getpoints() method. Currently, while executing the query keyword arguments or kwargs are not addressed. I'll issue a fix at the earliest.

MathewBiddle commented 1 year ago

If it helps, here is the workaround @ocefpaf came up with:

import pandas as pd

institution_id = '23070'

url = 'https://api.obis.org/v3/dataset?instituteid={}'.format(institution_id)

df = pd.read_json(url)
df = pd.DataFrame.from_records(df["results"])

df
ayushanand18 commented 1 year ago

I think, a simple fix in the package would be just replacing args with {**args, **kwargs} while passing the arguments for a GET request. Works for Python 3.5+

MathewBiddle commented 1 year ago

Is this pushed out (ie can I conda update pyobis) or do I need to install from github?

ayushanand18 commented 1 year ago

This has not been released yet, and I think we should make a patch release for this now.

ayushanand18 commented 1 year ago

The release has been successfully pushed out on PyPI now.

MathewBiddle commented 1 year ago

Thank you @ayushanand18 and @7yl4r ! This works now.

Expect a new notebook in the IOOS CodeLab soon!