Skip to content

Commit fb97ec2

Browse files
committed
Corrected logic to comply with #113
* Also converted unit test to test the process.py logic instead of the validity of the params file. * Corrected errors I'd introduced in the conversion to covidcast client
1 parent eb19aa4 commit fb97ec2

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

safegraph/delphi_safegraph/process.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,30 @@ def add_prefix(signal_names, wip_signal, prefix: str):
1717
prefix : 'wip_'
1818
prefix for new/non public signals
1919
wip_signal : List[str] or bool
20-
Either takes a list of wip signals: [], OR
21-
incorporated all signals in the registry: True OR
22-
no signals: False
20+
a list of wip signals: [], OR
21+
all signals in the registry: True OR
22+
only signals that have never been published: False
2323
Returns
2424
-------
2525
List of signal names
2626
wip/non wip signals for further computation
2727
"""
2828

29-
if wip_signal in ("", False):
30-
return signal_names
31-
elif wip_signal and isinstance(wip_signal, bool):
29+
if wip_signal is True:
30+
return [prefix + signal for signal in signal_names]
31+
if isinstance(wip_signal,list):
32+
make_wip = set(wip_signal)
3233
return [
33-
(prefix + signal) if public_signal(signal)
34-
else signal
34+
(prefix if signal in make_wip else "") + signal
3535
for signal in signal_names
3636
]
37-
elif isinstance(wip_signal, list):
38-
for signal in wip_signal:
39-
if public_signal(signal):
40-
signal_names.append(prefix + signal)
41-
signal_names.remove(signal)
42-
return signal_names
43-
else:
44-
raise ValueError("Supply True | False or '' or [] | list()")
45-
37+
if wip_signal in {False,""}:
38+
return [
39+
signal if public_signal(signal)
40+
else prefix + signal
41+
for signal in signal_names
42+
]
43+
raise ValueError("Supply True | False or '' or [] | list()")
4644

4745
# Check if the signal name is public
4846
def public_signal(signal_):
@@ -54,15 +52,14 @@ def public_signal(signal_):
5452
Returns
5553
-------
5654
bool
57-
True if the signal is not present
58-
False if the signal is present
55+
True if the signal is present
56+
False if the signal is not present
5957
"""
60-
epidata_df = covidcast.meta()
58+
epidata_df = covidcast.metadata()
6159
for index in range(len(epidata_df)):
62-
if 'signal' in epidata_df[index]:
63-
if epidata_df[index]['signal'] == signal_:
64-
return False
65-
return True
60+
if epidata_df['signal'][index] == signal_:
61+
return True
62+
return False
6663

6764

6865
def construct_signals(cbg_df, signal_names):

safegraph/tests/test_process.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,17 @@ def test_aggregate_state(self):
5050
assert np.all(x[~np.isnan(x)] >= 0)
5151

5252
def test_handle_wip_signal(self):
53-
wip_signal = read_params()["wip_signal"]
54-
assert isinstance(wip_signal, (list, bool)) or wip_signal == "", "Supply True | False or "" or [] | list()"
55-
if isinstance(wip_signal, list):
56-
assert set(wip_signal).issubset(set(SIGNALS)), "signal in params don't belong in the registry"
57-
updated_signal_names = add_prefix(SIGNALS, wip_signal, prefix='wip_')
58-
assert (len(updated_signal_names) >= len(SIGNALS))
53+
# Test wip_signal = True
54+
signal_names = add_prefix(SIGNALS, True, prefix="wip_")
55+
assert all(s.startswith("wip_") for s in signal_names)
56+
# Test wip_signal = list
57+
signal_names = add_prefix(SIGNALS, [SIGNALS[0]], prefix="wip_")
58+
assert signal_names[0].startswith("wip_")
59+
assert all(not s.startswith("wip_") for s in signal_names[1:])
60+
# Test wip_signal = False
61+
signal_names = add_prefix(["xyzzy", SIGNALS[0]], False, prefix="wip_")
62+
assert signal_names[0].startswith("wip_")
63+
assert all(not s.startswith("wip_") for s in signal_names[1:])
5964

6065

6166

0 commit comments

Comments
 (0)