Skip to content

Fix linting on delphi utils #465

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
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions _delphi_utils_python/delphi_utils/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def run_module(archive_type: str,
Parameters
----------
archive_type: str
Type of ArchiveDiffer to run. Must be one of ["git", "s3"] which correspond to `GitArchiveDiffer` and `S3ArchiveDiffer`, respectively.
Type of ArchiveDiffer to run. Must be one of ["git", "s3"] which correspond to
`GitArchiveDiffer` and `S3ArchiveDiffer`, respectively.
cache_dir: str
The directory for storing most recent archived/uploaded CSVs to start diffing from.
export_dir: str
Expand Down Expand Up @@ -351,7 +352,7 @@ def update_cache(self):

self._cache_updated = True

def archive_exports(self,
def archive_exports(self, # pylint: disable=arguments-differ
exported_files: Files,
update_cache: bool = True,
update_s3: bool = True
Expand Down
1 change: 1 addition & 0 deletions _delphi_utils_python/delphi_utils/export.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Export data in the format expected by the Delphi API."""
# -*- coding: utf-8 -*-
from datetime import datetime
from os.path import join
Expand Down
11 changes: 5 additions & 6 deletions _delphi_utils_python/delphi_utils/geomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- remove deprecated functions once integration into JHU and Quidel is refactored
see: https://github.com/cmu-delphi/covidcast-indicators/issues/283
"""

# pylint: disable=too-many-lines
from os.path import join
import warnings
import pkg_resources
Expand Down Expand Up @@ -41,7 +41,7 @@
}


class GeoMapper:
class GeoMapper: # pylint: disable=too-many-public-methods
"""Geo mapping tools commonly used in Delphi.

The GeoMapper class provides utility functions for translating between different
Expand Down Expand Up @@ -301,7 +301,7 @@ def add_geocode(
df[from_col] = df[from_col].astype(str)

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

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

def convert_zip_to_msa(
self, data, zip_col="zip", msa_col="msa", date_col="date", count_cols=None
self, data, zip_col="zip", date_col="date", count_cols=None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's going on here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that variable is unused in that function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know if any indicators call it with that keyword?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't find any uses when I searched, only saw use of the zip_to_msa function below it, which calls convert_zip_to_msa.

):
"""DEPRECATED."""
warnings.warn(
Expand Down Expand Up @@ -828,7 +828,6 @@ def zip_to_msa(
data = self.convert_zip_to_msa(
data,
zip_col=zip_col,
msa_col=msa_col,
date_col=date_col,
count_cols=count_cols,
)
Expand Down
19 changes: 10 additions & 9 deletions _delphi_utils_python/delphi_utils/smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import pandas as pd


class Smoother:
class Smoother: # pylint: disable=too-many-instance-attributes
"""
This is the smoothing utility class. This class holds the parameter settings for its smoother
methods and provides reasonable defaults. Basic usage can be found in the examples below.
Expand Down Expand Up @@ -66,8 +66,8 @@ class Smoother:
Methods
----------
smooth: np.ndarray or pd.Series
Takes a 1D signal and returns a smoothed version. The input and the output have the same length
and type.
Takes a 1D signal and returns a smoothed version.
The input and the output have the same lengthand type.

Example Usage
-------------
Expand Down Expand Up @@ -244,20 +244,21 @@ def left_gauss_linear_smoother(self, signal):
)
n = len(signal)
signal_smoothed = np.zeros_like(signal)
A = np.vstack([np.ones(n), np.arange(n)]).T # the regression design matrix
# A is the regression design matrix
A = np.vstack([np.ones(n), np.arange(n)]).T # pylint: disable=invalid-name
for idx in range(n):
weights = np.exp(
-((np.arange(idx + 1) - idx) ** 2) / self.gaussian_bandwidth
)
AwA = np.dot(A[: (idx + 1), :].T * weights, A[: (idx + 1), :])
Awy = np.dot(
AwA = np.dot(A[: (idx + 1), :].T * weights, A[: (idx + 1), :]) # pylint: disable=invalid-name
Awy = np.dot( # pylint: disable=invalid-name
A[: (idx + 1), :].T * weights, signal[: (idx + 1)].reshape(-1, 1)
)
try:
beta = np.linalg.solve(AwA, Awy)
signal_smoothed[idx] = np.dot(A[: (idx + 1), :], beta)[-1]
except np.linalg.LinAlgError:
signal_smoothed[idx] = signal[idx] if self.impute else np.nan
signal_smoothed[idx] = signal[idx] if self.impute else np.nan # pylint: disable=using-constant-test
if self.minval is not None:
signal_smoothed[signal_smoothed <= self.minval] = self.minval
return signal_smoothed
Expand Down Expand Up @@ -318,7 +319,7 @@ def savgol_coeffs(self, nl, nr):
if nr > 0:
raise warnings.warn("The filter is no longer causal.")

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

Expand Down Expand Up @@ -367,7 +368,7 @@ def savgol_smoother(self, signal):
# - shortened_window (default) applies savgol with a smaller window to do the fit
# - identity keeps the original signal (doesn't smooth)
# - nan writes nans
if self.boundary_method == "shortened_window":
if self.boundary_method == "shortened_window": # pylint: disable=no-else-return
for ix in range(len(self.coeffs)):
if ix == 0:
signal_smoothed[ix] = signal[ix]
Expand Down
1 change: 1 addition & 0 deletions _delphi_utils_python/delphi_utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Read parameter files containing configuration information."""
# -*- coding: utf-8 -*-
from json import load
from os.path import exists
Expand Down