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

fix: Add workaround for warning from nbconvert. #19

Merged
merged 2 commits into from
Jul 26, 2023
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
6 changes: 5 additions & 1 deletion edvart/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from edvart.report_sections.table_of_contents import TableOfContents
from edvart.report_sections.timeseries_analysis import TimeseriesAnalysis
from edvart.report_sections.univariate_analysis import UnivariateAnalysis
from edvart.utils import env_var


class ReportBase(ABC):
Expand Down Expand Up @@ -225,7 +226,10 @@ def _export_html(

html_exporter = nbconvert.HTMLExporter(**html_exp_kwargs)

html = html_exporter.from_notebook_node(nb)[0]
# Workaround for a warning from `nbconvert` regarding debugging
# and frozen modules. We are not debugging, so we can safely ignore it.
with env_var("PYDEVD_DISABLE_FILE_VALIDATION", "1"):
html = html_exporter.from_notebook_node(nb)[0]

# Save HTML to file
with open(html_filepath, "w") as html_file:
Expand Down
24 changes: 23 additions & 1 deletion edvart/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Utils package."""

from typing import Any, Dict, Iterable, List, Literal, Optional, Tuple, Union
import os
from contextlib import contextmanager
from typing import Any, Dict, Iterable, Iterator, List, Literal, Optional, Tuple, Union

import pandas as pd
import seaborn as sns
Expand Down Expand Up @@ -542,3 +544,23 @@ def contingency_table(df: pd.DataFrame) -> pd.DataFrame:
"""
table = sm.stats.Table.from_data(df)
return table.table_orig.astype(int)


@contextmanager
def env_var(name: str, value: str) -> Iterator[None]:
"""
Set an environment variable for the duration of the context.

Parameters
----------
name : str
Name of the environment variable.
value : str
Value of the environment variable.
"""
original_env = os.environ.copy()
os.environ[name] = value
try:
yield
finally:
os.environ = original_env
9 changes: 9 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import math
import os
import warnings

import numpy as np
Expand Down Expand Up @@ -31,3 +32,11 @@ def test_full_na_series():
assert utils.is_numeric(series)
assert utils.is_categorical(series)
assert utils.num_unique_values(series) == 0


def test_env_var():
test_var_name = "TEST_VAR"
test_var_value = "test"
with utils.env_var(test_var_name, test_var_value):
assert os.environ[test_var_name] == test_var_value
assert test_var_value not in os.environ