Skip to content

Commit ce365b7

Browse files
committed
migrate most indicators to common add_prefix
1 parent 0b94c65 commit ce365b7

File tree

21 files changed

+24
-558
lines changed

21 files changed

+24
-558
lines changed

_delphi_utils_python/delphi_utils/signal.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""Functions for understanding and creating signal names."""
22
import covidcast
33

4-
def add_prefix(signal_names, wip_signal, prefix: str):
4+
def add_prefix(signal_names, wip_signal, prefix="wip_"):
55
"""Adds prefix to signal if there is a WIP signal
66
Parameters
77
----------
88
signal_names: List[str]
99
Names of signals to be exported
10-
prefix : 'wip_'
10+
prefix : "wip_"
1111
prefix for new/non public signals
1212
wip_signal : List[str] or bool
1313
a list of wip signals: [], OR
@@ -50,6 +50,6 @@ def public_signal(signal):
5050
"""
5151
epidata_df = covidcast.metadata()
5252
for index in range(len(epidata_df)):
53-
if epidata_df['signal'][index] == signal:
53+
if epidata_df["signal"][index] == signal:
5454
return True
5555
return False

_template_python/delphi_NAME/handle_wip_signal.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

_template_python/tests/test_handle_wip_signal.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

cdc_covidnet/delphi_cdc_covidnet/update_sensor.py

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import numpy as np
1313
import pandas as pd
1414

15-
from delphi_utils import read_params
15+
from delphi_utils import read_params, add_prefix
1616
import covidcast
1717
from .api_config import APIConfig
1818
from .covidnet import CovidNet
@@ -101,57 +101,3 @@ def update_sensor(
101101
write_to_csv(hosp_df, signal, output_path)
102102

103103
return hosp_df
104-
105-
106-
def add_prefix(signal_names, wip_signal, prefix):
107-
"""Adds prefix to signal if there is a WIP signal
108-
Parameters
109-
----------
110-
signal_names: List[str]
111-
Names of signals to be exported
112-
prefix : 'wip_'
113-
prefix for new/non public signals
114-
wip_signal : List[str] or bool
115-
a list of wip signals: [], OR
116-
all signals in the registry: True OR
117-
only signals that have never been published: False
118-
Returns
119-
-------
120-
List of signal names
121-
wip/non wip signals for further computation
122-
"""
123-
124-
if wip_signal is True:
125-
return [prefix + signal for signal in signal_names]
126-
if isinstance(wip_signal, list):
127-
make_wip = set(wip_signal)
128-
return [
129-
(prefix if signal in make_wip else "") + signal
130-
for signal in signal_names
131-
]
132-
if wip_signal in {False, ""}:
133-
return [
134-
signal if public_signal(signal)
135-
else prefix + signal
136-
for signal in signal_names
137-
]
138-
raise ValueError("Supply True | False or '' or [] | list()")
139-
140-
141-
def public_signal(signal_):
142-
"""Checks if the signal name is already public using COVIDcast
143-
Parameters
144-
----------
145-
signal_ : str
146-
Name of the signal
147-
Returns
148-
-------
149-
bool
150-
True if the signal is present
151-
False if the signal is not present
152-
"""
153-
epidata_df = covidcast.metadata()
154-
for index in range(len(epidata_df)):
155-
if epidata_df['signal'][index] == signal_:
156-
return True
157-
return False

cdc_covidnet/tests/test_handle_wip_signal.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

combo_cases_and_deaths/delphi_combo_cases_and_deaths/handle_wip_signal.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

combo_cases_and_deaths/delphi_combo_cases_and_deaths/run.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
import covidcast
1414
import pandas as pd
1515

16-
from delphi_utils import read_params
16+
from delphi_utils import read_params, add_prefix
1717
from .constants import METRICS, SMOOTH_TYPES, SENSORS, GEO_RESOLUTIONS
18-
from .handle_wip_signal import add_prefix
1918

2019

2120
def check_none_data_frame(data_frame, label, date_range):

combo_cases_and_deaths/tests/test_run.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pandas as pd
66

77
from delphi_combo_cases_and_deaths.run import extend_raw_date_range, sensor_signal, combine_usafacts_and_jhu, COLUMN_MAPPING
8-
from delphi_combo_cases_and_deaths.handle_wip_signal import add_prefix
98
from delphi_utils import read_params
109
from delphi_combo_cases_and_deaths.constants import METRICS, SMOOTH_TYPES, SENSORS, GEO_RESOLUTIONS
1110

@@ -36,28 +35,6 @@ def test_issue_dates():
3635
"""
3736

3837

39-
def test_handle_wip_signal():
40-
"""Verify that "wip_" prefixes are being applied appropriately.
41-
"""
42-
signal_list = [sensor_signal(metric, sensor, smoother)[1]
43-
for (metric, sensor, smoother) in
44-
product(METRICS, SENSORS, SMOOTH_TYPES)]
45-
46-
# Test wip_signal = True (all signals should receive prefix)
47-
signal_names = add_prefix(signal_list, True, prefix="wip_")
48-
assert all(s.startswith("wip_") for s in signal_names)
49-
50-
# Test wip_signal = list (only listed signals should receive prefix)
51-
signal_names = add_prefix(signal_list, [signal_list[0]], prefix="wip_")
52-
print(signal_names)
53-
assert signal_names[0].startswith("wip_")
54-
assert all(not s.startswith("wip_") for s in signal_names[1:])
55-
56-
# Test wip_signal = False (only unpublished signals should receive prefix)
57-
signal_names = add_prefix(["xyzzy", signal_list[0]], False, prefix="wip_")
58-
assert signal_names[0].startswith("wip_")
59-
assert all(not s.startswith("wip_") for s in signal_names[1:])
60-
6138
def test_unstable_sources():
6239
"""Verify that combine_usafacts_and_jhu assembles the combined data
6340
frame correctly for all cases where 0, 1, or both signals are

emr_hosp/delphi_emr_hosp/update_sensor.py

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from datetime import timedelta
99
from multiprocessing import Pool, cpu_count
1010
import covidcast
11-
from delphi_utils import GeoMapper, S3ArchiveDiffer, read_params
11+
from delphi_utils import GeoMapper, S3ArchiveDiffer, read_params, add_prefix
1212

1313
# third party
1414
import numpy as np
@@ -70,59 +70,6 @@ def write_to_csv(output_dict, write_se, out_name, output_path="."):
7070
logging.debug(f"wrote {out_n} rows for {len(geo_ids)} {geo_level}")
7171

7272

73-
def add_prefix(signal_names, wip_signal, prefix="wip_"):
74-
"""Adds prefix to signal if there is a WIP signal
75-
Parameters
76-
----------
77-
signal_names: List[str]
78-
Names of signals to be exported
79-
wip_signal : List[str] or bool
80-
a list of wip signals: [], OR
81-
all signals in the registry: True OR
82-
only signals that have never been published: False
83-
prefix : 'wip_'
84-
prefix for new/non public signals
85-
Returns
86-
-------
87-
List of signal names
88-
wip/non wip signals for further computation
89-
"""
90-
if wip_signal is True:
91-
return [prefix + signal for signal in signal_names]
92-
if isinstance(wip_signal, list):
93-
make_wip = set(wip_signal)
94-
return [
95-
prefix + signal if signal in make_wip else signal
96-
for signal in signal_names
97-
]
98-
if wip_signal in {False, ""}:
99-
return [
100-
signal if public_signal(signal)
101-
else prefix + signal
102-
for signal in signal_names
103-
]
104-
raise ValueError("Supply True | False or '' or [] | list()")
105-
106-
107-
def public_signal(signal_):
108-
"""Checks if the signal name is already public using COVIDcast
109-
Parameters
110-
----------
111-
signal_ : str
112-
Name of the signal
113-
Returns
114-
-------
115-
bool
116-
True if the signal is present
117-
False if the signal is not present
118-
"""
119-
epidata_df = covidcast.metadata()
120-
for index in range(len(epidata_df)):
121-
if epidata_df['signal'][index] == signal_:
122-
return True
123-
return False
124-
125-
12673
class EMRHospSensorUpdator:
12774

12875
def __init__(self,

0 commit comments

Comments
 (0)