Skip to content
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

Linting #5

Merged
merged 18 commits into from
Apr 17, 2024
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 .github/workflows/databricks_pull_request_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Run test notebook
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: linting

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip' # caching pip dependencies
- run: pip install pylint
- run: pip install databricks-labs-pylint
- run: pylint --load-plugins=databricks.labs.pylint.all covid_analysis/transforms.py
22 changes: 11 additions & 11 deletions covid_analysis/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

# Filter by country code.
def filter_country(pdf, country="USA"):
pdf = pdf[pdf.iso_code == country]
return pdf
pdf = pdf[pdf.iso_code == country]
return pdf

# Pivot by indicator, and fill missing values.
def pivot_and_clean(pdf, fillna):
pdf["value"] = pd.to_numeric(pdf["value"])
pdf = pdf.fillna(fillna).pivot_table(
values="value", columns="indicator", index="date"
)
return pdf
pdf["value"] = pd.to_numeric(pdf["value"])
pdf = pdf.fillna(fillna).pivot_table(
values="value", columns="indicator", index="date"
)
return pdf

# Create column names that are compatible with Delta tables.
def clean_spark_cols(pdf):
pdf.columns = pdf.columns.str.replace(" ", "_")
return pdf
pdf.columns = pdf.columns.str.replace(" ", "_")
return pdf

# Convert index to column (works with pandas API on Spark, too).
def index_to_col(df, colname):
df[colname] = df.index
return df
df[colname] = df.index
return df
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.pylint.main]
load-plugins = "databricks.labs.pylint.all"
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ python-dateutil==2.8.2
pytz==2022.1
six==1.16.0
tomli==2.0.1
wget==3.2
wget==3.2
databricks-labs-pylint
Loading