Skip to content

Commit

Permalink
fix(eda): suppress warnings for missing and report
Browse files Browse the repository at this point in the history
  • Loading branch information
jinglinpeng committed Apr 21, 2021
1 parent b2eb14d commit df2a1e7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
13 changes: 13 additions & 0 deletions dataprep/eda/create_report/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This module implements the create_report(df) function.
"""
import warnings
from typing import Any, Dict, List, Optional

import pandas as pd
Expand Down Expand Up @@ -59,6 +60,7 @@ def create_report(
>>> report.save('My Fantastic Report') # save report to local disk
>>> report.show_browser() # show report in the browser
"""
suppress_warnings()
cfg = Config.from_dict(display, config)
context = {
"resources": INLINE.render(),
Expand All @@ -68,3 +70,14 @@ def create_report(
template_base = ENV_LOADER.get_template("base.html")
report = template_base.render(context=context)
return Report(report)


def suppress_warnings() -> None:
"""
suppress warnings in create_report
"""
warnings.filterwarnings(
"ignore",
"The default value of regex will change from True to False in a future version",
category=FutureWarning,
)
33 changes: 24 additions & 9 deletions dataprep/eda/missing/compute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
calculating intermediate part
"""
from typing import Optional, cast, List, Any, Dict, Union
from warnings import catch_warnings, filterwarnings
import warnings
from scipy.cluster.hierarchy import ClusterWarning

from ...configs import Config
from ...data_array import DataArray, DataFrame
Expand Down Expand Up @@ -62,6 +63,7 @@ def compute_missing(
>>> plot_missing(df, "HDI_for_year")
>>> plot_missing(df, "HDI_for_year", "population")
"""
suppress_warnings()
df = preprocess_dataframe(df)
df = DataArray(df)

Expand All @@ -77,13 +79,26 @@ def compute_missing(
elif x is not None and y is not None:
ret = compute_missing_bivariate(df, x, y, cfg, dtype)
else:
# supress divide by 0 error due to heatmap
with catch_warnings():
filterwarnings(
"ignore",
"invalid value encountered in true_divide",
category=RuntimeWarning,
)
ret = compute_missing_nullivariate(df, cfg)
ret = compute_missing_nullivariate(df, cfg)

return cast(Intermediate, ret)


def suppress_warnings() -> None:
"""
suppress warnings for plot_missing
"""
warnings.filterwarnings(
"ignore",
"scipy.cluster: The symmetric non-negative hollow observation matrix looks "
+ "suspiciously like an uncondensed distance matrix",
category=ClusterWarning,
)
warnings.filterwarnings(
"ignore", "invalid value encountered in double_scalars", category=RuntimeWarning
)
warnings.filterwarnings(
"ignore",
"invalid value encountered in true_divide",
category=RuntimeWarning,
)

0 comments on commit df2a1e7

Please sign in to comment.