Skip to content

revert and deprecate async_epidata (+ Remove usage of PHP alias in the Python client) #1295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions integrations/client/test_delphi_epidata.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,25 +335,28 @@ def test_async_epidata(self):
]
self._insert_rows(rows)

test_output = Epidata.async_epidata('covidcast', [
self.params_from_row(rows[0]),
self.params_from_row(rows[1])
test_output = Epidata.async_epidata([
self.params_from_row(rows[0], source='covidcast'),
self.params_from_row(rows[1], source='covidcast')
]*12, batch_size=10)
responses = [i[0] for i in test_output]
# check response is same as standard covidcast call, using 24 calls to test batch sizing
responses = [i[0]["epidata"] for i in test_output]
# check response is same as standard covidcast call (minus fields omitted by the api.php endpoint),
# using 24 calls to test batch sizing
ignore_fields = ["source", "time_type", "geo_type"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

instead of re-defining, use existing list:

Suggested change
ignore_fields = ["source", "time_type", "geo_type"]
ignore_fields = CovidcastTestRow._api_row_compatibility_ignore_fields

self.assertEqual(
responses,
[
Epidata.covidcast(**self.params_from_row(rows[0])),
Epidata.covidcast(**self.params_from_row(rows[1])),
[{k: v for k, v in row.items() if k not in ignore_fields} for row in Epidata.covidcast(**self.params_from_row(rows[0]))["epidata"]],
[{k: v for k, v in row.items() if k not in ignore_fields} for row in Epidata.covidcast(**self.params_from_row(rows[1]))["epidata"]],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is slightly more concise...

Suggested change
[{k: v for k, v in row.items() if k not in ignore_fields} for row in Epidata.covidcast(**self.params_from_row(rows[0]))["epidata"]],
[{k: v for k, v in row.items() if k not in ignore_fields} for row in Epidata.covidcast(**self.params_from_row(rows[1]))["epidata"]],
[{k: row[k] for k in row.keys() - ignore_fields} for row in Epidata.covidcast(**self.params_from_row(rows[0]))["epidata"]],
[{k: row[k] for k in row.keys() - ignore_fields} for row in Epidata.covidcast(**self.params_from_row(rows[1]))["epidata"]],

]*12
)

@fake_epidata_endpoint
def test_async_epidata_fail(self):
with pytest.raises(ClientResponseError, match="404, message='NOT FOUND'"):
Epidata.async_epidata('covidcast', [
Epidata.async_epidata([
{
'source': 'covidcast',
'data_source': 'src',
'signals': 'sig',
'time_type': 'day',
Expand Down
11 changes: 7 additions & 4 deletions src/client/delphi_epidata.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,14 +691,17 @@ def covidcast_nowcast(
return Epidata._request("covidcast_nowcast", params)

@staticmethod
def async_epidata(endpoint, param_list, batch_size=50):
"""Make asynchronous Epidata calls for a list of parameters."""
def async_epidata(param_list, batch_size=50):
"""[DEPRECATED] Make asynchronous Epidata calls for a list of parameters."""

request_url = f"{Epidata.BASE_URL}/{endpoint}"
import warnings
warnings.filterwarnings("once", category=DeprecationWarning, module="delphi_epidata")
warnings.warn("Method `Epidata.async_epidata()` is deprecated and will be removed in a future version.",
category=DeprecationWarning)

async def async_get(params, session):
"""Helper function to make Epidata GET requests."""
async with session.get(request_url, params=params) as response:
async with session.get(f"{Epidata.BASE_URL}/api.php", params=params) as response:
response.raise_for_status()
return await response.json(), params

Expand Down