Skip to content

Conversation

@kthyng
Copy link
Contributor

@kthyng kthyng commented Apr 25, 2023

Currently you cannot input a keyword argument like "timeout" to urlopen because requests_kwargs and pandas_kwargs are not distinguished. Or, actually, in erddapy.py they are all just "**kw". The present changes make it so you can input keyword arguments to pandas, still not in a dict like it was, but can also specify keyword arguments to requests_kwargs.

Notes:

  • it looks like similar changes could happen in some of the other to_* functions but not sure and have not used those as much.
  • I see that requests_kwargs could instead be input to ERDDAP directly, but then that is not subsequently used. Not sure if both approaches should be allowed?

@kthyng
Copy link
Contributor Author

kthyng commented Apr 25, 2023

Example usage:

from erddapy import ERDDAP
server="https://erddap.sensors.ioos.us/erddap"
e = ERDDAP(server=server)
e.protocol = "tabledap"
# e.dataset_id = "cdmo_nerrs_bearcove"
e.dataset_id = "noaa_nos_co_ops_9455920"
e.to_pandas(**{"parse_dates": [0], "index_col": 0}, requests_kwargs={"timeout": 60})

Read in for noaa_nos_co_ops_9455920 will only work if the input for requests_kwargs is working correctly.

I wasn't sure how to make a test for this that just checked to make sure the keywords made it through.

@kthyng
Copy link
Contributor Author

kthyng commented Apr 27, 2023

@ocefpaf if you get a moment could you see what you think of this?

response = kw.pop("response", "csvp")
url = self.get_download_url(response=response, **kw)
return to_pandas(url, pandas_kwargs=dict(**kw))
url = self.get_download_url(response=response, **(distinct_kwargs or {}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

distinct should not be a kw. I guess we never noticed. We should make the default False and make it a regular arg. Do you mind adding that to your PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I changed that in erddapy.py but didn't make changes in url.py in case that would cause some backward incompatibility issues, but I could propagate it through if you want.

@kthyng
Copy link
Contributor Author

kthyng commented May 1, 2023

@ocefpaf Does this look ok to you at this point? Note that I didn't change any of the other _to_* functions.

@kthyng
Copy link
Contributor Author

kthyng commented May 10, 2023

Ping @ocefpaf 😅 I'm using this locally for now but eventually will need to be able to use it otherwise so just want to keep this around.

@kthyng
Copy link
Contributor Author

kthyng commented May 22, 2023

@ocefpaf Might you have a chance to merge this? I hope it is ready to go.

@ocefpaf ocefpaf force-pushed the using_requests_kwargs branch from 40d37bf to 046a8b0 Compare June 21, 2023 17:22
ocefpaf and others added 4 commits June 21, 2023 15:11
quote>
quote> Current you cannot input a keyword argument like "timeout" to urlopen because requests_kwargs and pandas_kwargs are not distinguished. Or, actually, in erddapy.py they are all just "**kw". The present changes make it so you can input keyword arguments to pandas, still not in a dict like it was, but can also specify keyword arguments to requests_kwargs.
quote>
quote> Notes:
quote> * it looks like similar changes could happen in some of the other to_* functions but not sure and have not used those as much.
quote> * I see that requests_kwargs could instead be input to ERDDAP directly, but then that is not subsequently used. Not sure if both approaches should be allowed?
@ocefpaf ocefpaf force-pushed the using_requests_kwargs branch from 046a8b0 to 0e33e77 Compare June 21, 2023 18:18
@ocefpaf ocefpaf merged commit 59ce5fb into ioos:main Jun 21, 2023
@ocefpaf
Copy link
Member

ocefpaf commented Jun 21, 2023

My internal handling/passing of all the kw is still messy but I think things are a bit more consistent now.
Thanks for the PR!

@kthyng
Copy link
Contributor Author

kthyng commented Jul 19, 2023

Thanks @ocefpaf!

@kthyng kthyng deleted the using_requests_kwargs branch November 27, 2023 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants