Skip to content

Commit 6681a47

Browse files
authored
Merge pull request #465 from cmu-delphi/utils-lint
Fix linting on delphi utils
2 parents bcf412d + f42f045 commit 6681a47

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

_delphi_utils_python/delphi_utils/archive.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ def run_module(archive_type: str,
104104
Parameters
105105
----------
106106
archive_type: str
107-
Type of ArchiveDiffer to run. Must be one of ["git", "s3"] which correspond to `GitArchiveDiffer` and `S3ArchiveDiffer`, respectively.
107+
Type of ArchiveDiffer to run. Must be one of ["git", "s3"] which correspond to
108+
`GitArchiveDiffer` and `S3ArchiveDiffer`, respectively.
108109
cache_dir: str
109110
The directory for storing most recent archived/uploaded CSVs to start diffing from.
110111
export_dir: str
@@ -351,7 +352,7 @@ def update_cache(self):
351352

352353
self._cache_updated = True
353354

354-
def archive_exports(self,
355+
def archive_exports(self, # pylint: disable=arguments-differ
355356
exported_files: Files,
356357
update_cache: bool = True,
357358
update_s3: bool = True

_delphi_utils_python/delphi_utils/export.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Export data in the format expected by the Delphi API."""
12
# -*- coding: utf-8 -*-
23
from datetime import datetime
34
from os.path import join

_delphi_utils_python/delphi_utils/geomap.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- remove deprecated functions once integration into JHU and Quidel is refactored
1010
see: https://github.com/cmu-delphi/covidcast-indicators/issues/283
1111
"""
12-
12+
# pylint: disable=too-many-lines
1313
from os.path import join
1414
import warnings
1515
import pkg_resources
@@ -41,7 +41,7 @@
4141
}
4242

4343

44-
class GeoMapper:
44+
class GeoMapper: # pylint: disable=too-many-public-methods
4545
"""Geo mapping tools commonly used in Delphi.
4646
4747
The GeoMapper class provides utility functions for translating between different
@@ -301,7 +301,7 @@ def add_geocode(
301301
df[from_col] = df[from_col].astype(str)
302302

303303
# Assuming that the passed-in records are all United States data, at the moment
304-
if (from_code, new_code) in [("fips", "nation"), ("zip", "nation")]:
304+
if (from_code, new_code) in [("fips", "nation"), ("zip", "nation")]: # pylint: disable=no-else-return
305305
df[new_col] = df[from_col].apply(lambda x: "us")
306306
return df
307307
elif new_code == "nation":
@@ -724,7 +724,7 @@ def convert_state_code_to_state_id(
724724
)
725725

726726
state_table = self._load_crosswalk(from_code="state", to_code="state")
727-
state_table = state_table[["state_code", "state_id"]].rename(
727+
state_table = state_table[["state_code", "state_id"]].rename( # pylint: disable=unsubscriptable-object
728728
columns={"state_id": state_id_col}
729729
)
730730
data = data.copy()
@@ -796,7 +796,7 @@ def convert_zip_to_hrr(self, data, zip_col="zip", hrr_col="hrr"):
796796
return data
797797

798798
def convert_zip_to_msa(
799-
self, data, zip_col="zip", msa_col="msa", date_col="date", count_cols=None
799+
self, data, zip_col="zip", date_col="date", count_cols=None
800800
):
801801
"""DEPRECATED."""
802802
warnings.warn(
@@ -828,7 +828,6 @@ def zip_to_msa(
828828
data = self.convert_zip_to_msa(
829829
data,
830830
zip_col=zip_col,
831-
msa_col=msa_col,
832831
date_col=date_col,
833832
count_cols=count_cols,
834833
)

_delphi_utils_python/delphi_utils/smooth.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import pandas as pd
1919

2020

21-
class Smoother:
21+
class Smoother: # pylint: disable=too-many-instance-attributes
2222
"""Smoother class.
2323
2424
This is the smoothing utility class. This class holds the parameter settings for its smoother
@@ -78,8 +78,8 @@ class Smoother:
7878
Methods
7979
----------
8080
smooth: np.ndarray or pd.Series
81-
Takes a 1D signal and returns a smoothed version. The input and the output have the same
82-
length and type.
81+
Takes a 1D signal and returns a smoothed version.
82+
The input and the output have the same length and type.
8383
8484
Example Usage
8585
-------------
@@ -260,20 +260,21 @@ def left_gauss_linear_smoother(self, signal):
260260
)
261261
n = len(signal)
262262
signal_smoothed = np.zeros_like(signal)
263-
A = np.vstack([np.ones(n), np.arange(n)]).T # the regression design matrix
263+
# A is the regression design matrix
264+
A = np.vstack([np.ones(n), np.arange(n)]).T # pylint: disable=invalid-name
264265
for idx in range(n):
265266
weights = np.exp(
266267
-((np.arange(idx + 1) - idx) ** 2) / self.gaussian_bandwidth
267268
)
268-
AwA = np.dot(A[: (idx + 1), :].T * weights, A[: (idx + 1), :])
269-
Awy = np.dot(
269+
AwA = np.dot(A[: (idx + 1), :].T * weights, A[: (idx + 1), :]) # pylint: disable=invalid-name
270+
Awy = np.dot( # pylint: disable=invalid-name
270271
A[: (idx + 1), :].T * weights, signal[: (idx + 1)].reshape(-1, 1)
271272
)
272273
try:
273274
beta = np.linalg.solve(AwA, Awy)
274275
signal_smoothed[idx] = np.dot(A[: (idx + 1), :], beta)[-1]
275276
except np.linalg.LinAlgError:
276-
signal_smoothed[idx] = signal[idx] if self.impute else np.nan
277+
signal_smoothed[idx] = signal[idx] if self.impute else np.nan # pylint: disable=using-constant-test
277278
if self.minval is not None:
278279
signal_smoothed[signal_smoothed <= self.minval] = self.minval
279280
return signal_smoothed
@@ -336,7 +337,7 @@ def savgol_coeffs(self, nl, nr):
336337
if nr > 0:
337338
raise warnings.warn("The filter is no longer causal.")
338339

339-
A = np.vstack(
340+
A = np.vstack( # pylint: disable=invalid-name
340341
[np.arange(nl, nr + 1) ** j for j in range(self.poly_fit_degree + 1)]
341342
).T
342343

@@ -380,7 +381,7 @@ def savgol_smoother(self, signal):
380381
# - shortened_window (default) applies savgol with a smaller window to do the fit
381382
# - identity keeps the original signal (doesn't smooth)
382383
# - nan writes nans
383-
if self.boundary_method == "shortened_window":
384+
if self.boundary_method == "shortened_window": # pylint: disable=no-else-return
384385
for ix in range(len(self.coeffs)):
385386
if ix == 0:
386387
signal_smoothed[ix] = signal[ix]

_delphi_utils_python/delphi_utils/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Read parameter files containing configuration information."""
12
# -*- coding: utf-8 -*-
23
from json import load
34
from os.path import exists

0 commit comments

Comments
 (0)