Skip to content

Commit

Permalink
Merge pull request #1295 from cmu-delphi/revert_deprecate_async_epidata
Browse files Browse the repository at this point in the history
revert and deprecate async_epidata (+ Remove usage of PHP alias in the Python client)
  • Loading branch information
melange396 authored Oct 4, 2023
2 parents 5f0b521 + 65d1587 commit 1f9bf19
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
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 = 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: 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

0 comments on commit 1f9bf19

Please sign in to comment.