Skip to content

Release covidcast-indicators 0.1.17 #1275

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 60 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
8c752d9
Update utilities for NAN codes:
dshemetov Feb 10, 2021
83cb333
Nans: update archiver deletion handling
dshemetov May 12, 2021
cd140b1
Nans: update archiver deletion
dshemetov May 13, 2021
7a9e45c
Nancodes archiver: rename variable for clarity
dshemetov Aug 31, 2021
6069aee
Merge branch 'main' into nancodes
dshemetov Aug 31, 2021
19e8be4
Nancodes archiver: small formatting change
dshemetov Aug 31, 2021
3c21731
Merge pull request #1246 from cmu-delphi/bot/sync-prod-main
krivard Sep 14, 2021
01e7b3d
un-retire schooling indicators from sirCAL
nmdefries Sep 14, 2021
91bb0ad
Build facebook container image
korlaxxalrok Sep 15, 2021
a755153
Merge pull request #1248 from cmu-delphi/update-container-build-workflow
krivard Sep 15, 2021
616ca89
break line
nmdefries Sep 15, 2021
1db3077
add closing bracket
nmdefries Sep 15, 2021
0b5388c
Merge pull request #1247 from cmu-delphi/turn-schooling-inds-back-on
krivard Sep 15, 2021
7aac1de
Nancodes: make linter happy
dshemetov Sep 15, 2021
e07d9cb
Merge branch 'main' into nancodes
dshemetov Sep 15, 2021
b4e66ce
Correctly ignore all receiving/*.csv files
dshemetov Sep 15, 2021
8428004
Update setup.py files to "Python :: 3.8" annotation
dshemetov Sep 15, 2021
7937a68
Merge pull request #1251 from cmu-delphi/removepy37refs
krivard Sep 16, 2021
d1c063b
check if readr is installed
nmdefries Sep 16, 2021
0c0ca18
Merge pull request #1250 from cmu-delphi/gitignore
krivard Sep 16, 2021
efd9423
Fix value check in quidel data_tools
alexcoda Sep 19, 2021
77f26f7
Replace print statements with logging
alexcoda Sep 19, 2021
f2f55d3
lint
alexcoda Sep 19, 2021
23c134a
lint
alexcoda Sep 19, 2021
f582551
Fix missing logger in tests
alexcoda Sep 19, 2021
bb3121d
Fix missing logger in tests
alexcoda Sep 19, 2021
39e7dff
Instantiate logger correctly in tests
alexcoda Sep 19, 2021
af7a90e
Fix error check
alexcoda Sep 19, 2021
985e98b
only install remotes if not avail; upgrade as needed
nmdefries Sep 20, 2021
b32ed7f
test run with no cache
nmdefries Sep 20, 2021
3669748
Revert "test run with no cache"
nmdefries Sep 20, 2021
a53e36c
Merge pull request #1253 from cmu-delphi/survey-tests-robust-no-cache
krivard Sep 20, 2021
25f1b4e
set E2 to integer on read
nmdefries Sep 20, 2021
056ad81
Add new host to inventory
korlaxxalrok Sep 21, 2021
9ff405f
Re-add primary back to inventory
korlaxxalrok Sep 21, 2021
5f5b292
Update quidel/delphi_quidel/pull.py
alexcoda Sep 22, 2021
18ae072
Update quidel/delphi_quidel/pull.py
alexcoda Sep 22, 2021
1aa181c
Update quidel_covidtest/delphi_quidel_covidtest/pull.py
alexcoda Sep 22, 2021
b6361de
Update quidel_covidtest/delphi_quidel_covidtest/pull.py
alexcoda Sep 22, 2021
8b22079
Switch CDC Covidnet to use structed logger
chinandrew Sep 22, 2021
c7272fc
Switch to structed logger for ChangeHC
chinandrew Sep 22, 2021
5b56357
switch doctor visits to structured logger
chinandrew Sep 22, 2021
c63a454
Remove bare except in DV
chinandrew Sep 22, 2021
dd3b8f5
Merge pull request #1257 from cmu-delphi/check-remotes-installed
krivard Sep 22, 2021
c4a57fc
Merge pull request #1256 from alexcoda/standardize-logging
krivard Sep 22, 2021
a6b3ffe
Merge pull request #1260 from cmu-delphi/add-bigchunk-as-deploy-target
krivard Sep 22, 2021
547a099
Merge pull request #1262 from cmu-delphi/except
krivard Sep 22, 2021
086cf40
Merge pull request #1259 from cmu-delphi/set-E2-read-types
krivard Sep 22, 2021
ec697ed
Nancodes archiver: remove deleted file nan replacements
dshemetov Sep 22, 2021
50bf96b
Refactor NCHS mortality to use delphi export util
chinandrew Sep 25, 2021
5fa6314
Remove test for old export func
chinandrew Sep 25, 2021
cdd12ff
Merge pull request #1261 from cmu-delphi/use-structured-logger
krivard Sep 27, 2021
0e76a43
Merge pull request #1264 from cmu-delphi/nchs-export
krivard Sep 27, 2021
28ac486
Update archiver docstrings
dshemetov Sep 27, 2021
a46f866
Update archiver docstrings
dshemetov Sep 27, 2021
7cb9b8c
Nancodes archiver/export: explicit tests
dshemetov Sep 27, 2021
0ddf2aa
Merge branch 'main' into nancodes
dshemetov Sep 27, 2021
b5825a8
Merge pull request #1252 from dshemetov/nancodes
krivard Sep 28, 2021
baffc14
chore: bump delphi_utils to 0.1.13
Sep 29, 2021
3924981
chore: bump covidcast-indicators to 0.1.17
Sep 29, 2021
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 .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.16
current_version = 0.1.17
commit = True
message = chore: bump covidcast-indicators to {new_version}
tag = False
2 changes: 1 addition & 1 deletion .github/workflows/build-container-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
packages: [ "" ]
packages: [ facebook ]
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/r-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ jobs:
${{ runner.os }}-r-facebook-survey-
- name: Install R dependencies
run: |
if ( packageVersion("readr") != "1.4.0" ) {
if ( !require("readr") || packageVersion("readr") != "1.4.0" ) {
install.packages("devtools")
devtools::install_version("readr", version = "1.4.0")
}
install.packages("remotes")
remotes::update_packages(c("rcmdcheck", "mockr"), upgrade="always")

if ( !require("remotes") ) {
install.packages("remotes")
}
remotes::update_packages(c("rcmdcheck", "mockr", "remotes"), upgrade="always")
dependency_list <- remotes::dev_package_deps(dependencies=TRUE)
remotes::update_packages(dependency_list$package[dependency_list$package != "readr"], upgrade="always")
shell: Rscript {0}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
params.json

# Do not commit output files
receiving/*.csv
**/receiving/*.csv

# Do not commit hidden macOS files
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion _delphi_utils_python/.bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.12
current_version = 0.1.13
commit = True
message = chore: bump delphi_utils to {new_version}
tag = False
Expand Down
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 @@ -14,4 +14,4 @@
from .signal import add_prefix
from .nancodes import Nans

__version__ = "0.1.12"
__version__ = "0.1.13"
33 changes: 25 additions & 8 deletions _delphi_utils_python/delphi_utils/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
from git import Repo
from git.refs.head import Head
import pandas as pd
import numpy as np

from .utils import read_params
from .logger import get_structured_logger
from .nancodes import Nans

Files = List[str]
FileDiffMap = Dict[str, Optional[str]]
Expand Down Expand Up @@ -73,8 +75,10 @@ def diff_export_csv(
changed_df is the pd.DataFrame of common rows from after_csv with changed values.
added_df is the pd.DataFrame of added rows from after_csv.
"""
export_csv_dtypes = {"geo_id": str, "val": float,
"se": float, "sample_size": float}
export_csv_dtypes = {
"geo_id": str, "val": float, "se": float, "sample_size": float,
"missing_val": int, "missing_se": int, "missing_sample_size": int
}

before_df = pd.read_csv(before_csv, dtype=export_csv_dtypes)
before_df.set_index("geo_id", inplace=True)
Expand All @@ -89,12 +93,22 @@ def diff_export_csv(
before_df_cmn = before_df.reindex(common_idx)
after_df_cmn = after_df.reindex(common_idx)

# Exact comparisons, treating NA == NA as True
same_mask = before_df_cmn == after_df_cmn
same_mask |= pd.isna(before_df_cmn) & pd.isna(after_df_cmn)
# If CSVs have different columns (no missingness), mark all values as new
if ("missing_val" in before_df_cmn.columns) ^ ("missing_val" in after_df_cmn.columns):
same_mask = after_df_cmn.copy()
same_mask.loc[:] = False
else:
# Exact comparisons, treating NA == NA as True
same_mask = before_df_cmn == after_df_cmn
same_mask |= pd.isna(before_df_cmn) & pd.isna(after_df_cmn)

# Code deleted entries as nans with the deleted missing code
deleted_df = before_df.loc[deleted_idx, :].copy()
deleted_df[["val", "se", "sample_size"]] = np.nan
deleted_df[["missing_val", "missing_se", "missing_sample_size"]] = Nans.DELETED

return (
before_df.loc[deleted_idx, :],
deleted_df,
after_df_cmn.loc[~(same_mask.all(axis=1)), :],
after_df.loc[added_idx, :])

Expand Down Expand Up @@ -227,11 +241,11 @@ def diff_exports(self) -> Tuple[Files, FileDiffMap, Files]:

deleted_df, changed_df, added_df = diff_export_csv(
before_file, after_file)
new_issues_df = pd.concat([changed_df, added_df], axis=0)
new_issues_df = pd.concat([deleted_df, changed_df, added_df], axis=0)

if len(deleted_df) > 0:
print(
f"Warning, diff has deleted indices in {after_file} that will be ignored")
f"Diff has deleted indices in {after_file} that have been coded as nans.")

# Write the diffs to diff_file, if applicable
if len(new_issues_df) > 0:
Expand Down Expand Up @@ -414,6 +428,9 @@ def archive_exports(self, # pylint: disable=arguments-differ
archive_success.append(exported_file)
except FileNotFoundError:
archive_fail.append(exported_file)
except shutil.SameFileError:
# no need to copy if the cached file is the same
archive_success.append(exported_file)

self._exports_archived = True

Expand Down
53 changes: 49 additions & 4 deletions _delphi_utils_python/delphi_utils/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,33 @@
from datetime import datetime
from os.path import join
from typing import Optional
import logging

from epiweeks import Week
import numpy as np
import pandas as pd

from .nancodes import Nans

def filter_contradicting_missing_codes(df, sensor, metric, date, logger=None):
"""Find values with contradictory missingness codes, filter them, and log."""
columns = ["val", "se", "sample_size"]
# Get indicies where the XNOR is true (i.e. both are true or both are false).
masks = [
~(df[column].isna() ^ df["missing_" + column].eq(Nans.NOT_MISSING))
for column in columns
]
for mask in masks:
if not logger is None and df.loc[mask].size > 0:
logger.info(
"Filtering contradictory missing code in " +
"{0}_{1}_{2}.".format(sensor, metric, date.strftime(format="%Y-%m-%d"))
)
df = df.loc[~mask]
elif logger is None and df.loc[mask].size > 0:
df = df.loc[~mask]
return df

def create_export_csv(
df: pd.DataFrame,
export_dir: str,
Expand All @@ -16,7 +39,9 @@ def create_export_csv(
start_date: Optional[datetime] = None,
end_date: Optional[datetime] = None,
remove_null_samples: Optional[bool] = False,
write_empty_days: Optional[bool] = False
write_empty_days: Optional[bool] = False,
logger: Optional[logging.Logger] = None,
weekly_dates = False,
):
"""Export data in the format expected by the Delphi API.

Expand All @@ -43,6 +68,8 @@ def create_export_csv(
write_empty_days: Optional[bool]
If true, every day in between start_date and end_date will have a CSV file written
even if there is no data for the day. If false, only the days present are written.
logger: Optional[logging.Logger]
Pass a logger object here to log information about contradictory missing codes.

Returns
---------
Expand All @@ -65,12 +92,30 @@ def create_export_csv(
dates = pd.date_range(start_date, end_date)

for date in dates:
if weekly_dates:
t = Week.fromdate(pd.to_datetime(str(date)))
date_str = "weekly_" + str(t.year) + str(t.week).zfill(2)
else:
date_str = date.strftime('%Y%m%d')
if metric is None:
export_filename = f"{date.strftime('%Y%m%d')}_{geo_res}_{sensor}.csv"
export_filename = f"{date_str}_{geo_res}_{sensor}.csv"
else:
export_filename = f"{date.strftime('%Y%m%d')}_{geo_res}_{metric}_{sensor}.csv"
export_filename = f"{date_str}_{geo_res}_{metric}_{sensor}.csv"
export_file = join(export_dir, export_filename)
export_df = df[df["timestamp"] == date][["geo_id", "val", "se", "sample_size",]]
expected_columns = [
"geo_id",
"val",
"se",
"sample_size",
"missing_val",
"missing_se",
"missing_sample_size"
]
export_df = df[df["timestamp"] == date].filter(items=expected_columns)
if "missing_val" in export_df.columns:
export_df = filter_contradicting_missing_codes(
export_df, sensor, metric, date, logger=logger
)
if remove_null_samples:
export_df = export_df[export_df["sample_size"].notnull()]
export_df = export_df.round({"val": 7, "se": 7})
Expand Down
5 changes: 3 additions & 2 deletions _delphi_utils_python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
required = [
"boto3",
"covidcast",
"epiweeks",
"freezegun",
"gitpython",
"mock",
Expand All @@ -24,7 +25,7 @@

setup(
name="delphi_utils",
version="0.1.12",
version="0.1.13",
description="Shared Utility Functions for Indicators",
long_description=long_description,
long_description_content_type="text/markdown",
Expand All @@ -35,7 +36,7 @@
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
packages=find_packages(),
package_data={'': ['data/*.csv']}
Expand Down
Loading