Skip to content

Commit c2890b3

Browse files
committed
add warnings for unreasonable weekday effect
1 parent 0c65bb4 commit c2890b3

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

_delphi_utils_python/delphi_utils/weekday.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ def get_params(data, denominator_col, numerator_cols, date_col, scales, logger):
1919
series column in the data.
2020
"""
2121
tmp = data.reset_index()
22-
denoms = tmp.groupby(date_col).sum()[denominator_col]
23-
nums = tmp.groupby(date_col).sum()[numerator_cols]
24-
22+
denoms = tmp.groupby(date_col).sum(numeric_only = True)[denominator_col]
23+
nums = tmp.groupby(date_col).sum(numeric_only = True)[numerator_cols]
24+
if nums.shape[0] < 7:
25+
logger.warning("Trying to handle weekday effects with fewer than 7 days worth of data. This will probably not work.")
2526
# Construct design matrix to have weekday indicator columns and then day
2627
# indicators.
2728
X = np.zeros((nums.shape[0], 6 + nums.shape[0]))
@@ -40,7 +41,9 @@ def get_params(data, denominator_col, numerator_cols, date_col, scales, logger):
4041
logger.error("Unable to calculate weekday correction")
4142
else:
4243
params[i,:] = result
43-
44+
if np.exp(-params).max() == np.inf:
45+
logger.warning("largest weekday correction is infinite. Defaulting to no correction")
46+
params = np.zeros((nums.shape[1], X.shape[1]))
4447
return params
4548

4649
@staticmethod
@@ -93,11 +96,12 @@ def _fit(X, scales, npnums, npdenoms):
9396
for scale in scales:
9497
try:
9598
prob = cp.Problem(cp.Minimize((-ll + lmbda * penalty) / scale))
96-
_ = prob.solve()
99+
_ = prob.solve(solver = cp.ECOS)
97100
return b.value
98101
except SolverError:
99102
# If the magnitude of the objective function is too large, an error is
100103
# thrown; Rescale the objective function by going through loop
104+
print(f"Solver didn't work at {scale}x")
101105
continue
102106
return None
103107

doctor_visits/delphi_doctor_visits/download_claims_ftp_files.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@ def download(ftp_credentials, out_path, logger):
6161
client = paramiko.SSHClient()
6262
client.set_missing_host_key_policy(AllowAnythingPolicy())
6363

64-
client.connect(ftp_credentials["host"],
65-
username=ftp_credentials["user"],
66-
password=ftp_credentials["pass"],
67-
port=ftp_credentials["port"])
64+
client.connect(
65+
ftp_credentials["host"],
66+
username=ftp_credentials["user"],
67+
password=ftp_credentials["pass"],
68+
port=ftp_credentials["port"],
69+
allow_agent=False,
70+
look_for_keys=False,
71+
)
6872
sftp = client.open_sftp()
69-
sftp.chdir('/optum/receiving')
73+
sftp.chdir("/optum/receiving")
7074

7175
# go through files in recieving dir
7276
files_to_download = []

0 commit comments

Comments
 (0)