Skip to content

Commit

Permalink
Merge branch 'main' into bc_2168_cg
Browse files Browse the repository at this point in the history
  • Loading branch information
bchen1116 authored Sep 23, 2021
2 parents 8eda783 + 3cabb2c commit 8de1663
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ clean:
lint:
isort --check-only evalml
python docs/notebook_version_standardizer.py check-versions
python docs/notebook_version_standardizer.py check-execution
black evalml -t py39 --check
pydocstyle evalml/ --convention=google --add-ignore=D107 --add-select=D400 --match-dir='^(?!(tests)).*'
flake8 evalml
Expand Down
55 changes: 55 additions & 0 deletions docs/notebook_version_standardizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,40 @@ def _standardize_versions(notebooks, desired_version="3.8.6"):
_standardize_python_version(notebook, desired_version)


def _check_execution_and_output(notebook):
with open(notebook, "r") as f:
source = json.load(f)
for cells in source["cells"]:
if cells["cell_type"] == "code" and cells["execution_count"] != None:
return False
return True


def _fix_execution_and_output(notebook):
with open(notebook, "r") as f:
source = json.load(f)
for cells in source["cells"]:
if cells["cell_type"] == "code" and cells["execution_count"] != None:
cells["execution_count"] = None
cells["outputs"] = []
source["metadata"]["kernelspec"]["display_name"] = "Python 3"
source["metadata"]["kernelspec"]["name"] = "python3"
json.dump(source, open(notebook, "w"), indent=1)


def _get_notebooks_with_executions(notebooks):
executed = []
for notebook in notebooks:
if not _check_execution_and_output(notebook):
executed.append(notebook)
return executed


def _standardize_outputs(notebooks):
for notebook in notebooks:
_fix_execution_and_output(notebook)


@click.group()
def cli():
"""no-op"""
Expand Down Expand Up @@ -81,13 +115,34 @@ def standardize(desired_version):
different_versions = _get_notebooks_with_different_versions(
notebooks, desired_version
)
executed_notebooks = _get_notebooks_with_executions(notebooks)
if different_versions:
_standardize_versions(different_versions, desired_version)
different_versions = ["\t" + notebook for notebook in different_versions]
different_versions = "\n".join(different_versions)
click.echo(
f"Set the notebook version to {desired_version} for:\n {different_versions}"
)
if executed_notebooks:
_standardize_outputs(executed_notebooks)
executed_notebooks = ["\t" + notebook for notebook in executed_notebooks]
executed_notebooks = "\n".join(executed_notebooks)
click.echo(
f"Removed the outputs for:\n {executed_notebooks}"
)


@cli.command()
def check_execution():
notebooks = _get_ipython_notebooks(DOCS_PATH)
executed_notebooks = _get_notebooks_with_executions(notebooks)
if executed_notebooks:
executed_notebooks = ["\t" + notebook for notebook in executed_notebooks]
executed_notebooks = "\n".join(executed_notebooks)
raise SystemExit(
f"The following notebooks have executed outputs:\n {executed_notebooks}\n"
"Please run make lint-fix to fix this."
)


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions docs/source/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Release Notes
* Added validation to holdout data passed to ``predict`` and ``predict_proba`` for time series :pr:`2804`
* Added information about which row indices are outliers in ``OutliersDataCheck`` :pr:`2818`
* Added verbose flag to top level ``search()`` method :pr:`2813`
* Added support for linting jupyter notebooks and clearing the executed cells :pr:`2829`
* Added "DROP_ROWS" action to output of ``OutliersDataCheck.validate()`` :pr:`2820`
* Fixes
* Fixed bug where ``calculate_permutation_importance`` was not calculating the right value for pipelines with target transformers :pr:`2782`
Expand Down

0 comments on commit 8de1663

Please sign in to comment.