Skip to content

Remove public signal check from signal prefix #732

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 3 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion _delphi_utils_python/delphi_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
from .logger import get_structured_logger
from .geomap import GeoMapper
from .smooth import Smoother
from .signal import add_prefix, public_signal
from .signal import add_prefix

__version__ = "0.1.0"
28 changes: 2 additions & 26 deletions _delphi_utils_python/delphi_utils/signal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Functions for understanding and creating signal names."""
import covidcast


def add_prefix(signal_names, wip_signal, prefix="wip_"):
"""Add prefix to signal if there is a WIP signal.
Expand Down Expand Up @@ -28,29 +28,5 @@ def add_prefix(signal_names, wip_signal, prefix="wip_"):
for signal in signal_names
]
if wip_signal in {False, ""}:
return [
signal if public_signal(signal)
else prefix + signal
for signal in signal_names
]
return signal_names
raise ValueError("Supply True | False or '' or [] | list()")


def public_signal(signal):
"""Check if the signal name is already public using COVIDcast.

Parameters
----------
signal : str
Name of the signal
Returns
-------
bool
True if the signal is present
False if the signal is not present
"""
epidata_df = covidcast.metadata()
for index in range(len(epidata_df)):
if epidata_df["signal"][index] == signal:
return True
return False
18 changes: 5 additions & 13 deletions _delphi_utils_python/tests/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pandas as pd
import pytest
from delphi_utils.signal import add_prefix, public_signal
from delphi_utils.signal import add_prefix

# Constants for mocking out the call to `covidcast.metadata` within `public_signal()`.
PUBLIC_SIGNALS = ["sig1", "sig2", "sig3"]
Expand All @@ -26,15 +26,7 @@ def test_invalid_prefix_input(self):
with pytest.raises(ValueError):
add_prefix(None, None)

@patch("covidcast.metadata")
def test_add_prefix_to_non_public(self, metadata):
"""Tests that `add_prefix()` derives work-in-progress names for non-public signals."""
metadata.return_value = PUBLIC_SIGNALS_FRAME
assert add_prefix(["sig0", "sig1"], False, prefix="wip_") == ["wip_sig0", "sig1"]

@patch("covidcast.metadata")
def test_public_signal(self, metadata):
"""Tests that `public_signal()` identifies public vs. private signals."""
metadata.return_value = PUBLIC_SIGNALS_FRAME
assert not public_signal("sig0")
assert public_signal("sig2")
def test_add_no_prefix(self):
"""Tests that `add_prefix()` doesn't affect signals if `wip_signals` is False or ''."""
assert add_prefix(["sig0", "sig1"], False, prefix="wip_") == ["sig0", "sig1"]
assert add_prefix(["sig0", "sig1"], "", prefix="wip_") == ["sig0", "sig1"]
2 changes: 1 addition & 1 deletion cdc_covidnet/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class TestRun:
def test_match_old_to_new_output(self):
output_fnames = ["202010_state_wip_covidnet.csv", "202011_state_wip_covidnet.csv"]
output_fnames = ["202010_state_covidnet.csv", "202011_state_covidnet.csv"]
cached_files = [
"networkid_2_catchmentid_11.json",
"networkid_2_catchmentid_14.json",
Expand Down
4 changes: 2 additions & 2 deletions cdc_covidnet/tests/test_update_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ def test_syn_update_sensor(self):
assert pd.isna(hosp_df["sample_size"]).all()

# Check actual files generated
expected_files = ["202010_state_wip_covidnet.csv", "202011_state_wip_covidnet.csv"]
expected_files = ["202010_state_covidnet.csv", "202011_state_covidnet.csv"]
expected_files = [join(temp_dir, exp_file) for exp_file in expected_files]
for exp_file in expected_files:
assert exists(exp_file)
assert not exists("202012_state_wip_covidnet.csv")
assert not exists("202012_state_covidnet.csv")

for i, exp_file in enumerate(expected_files):
data = pd.read_csv(exp_file)
Expand Down