Skip to content

Commit

Permalink
Merge pull request #106 from ealcobaca/suppress-warnings
Browse files Browse the repository at this point in the history
Updated 'suppress_warnings' behavior in MFE .extract and .fit methods
  • Loading branch information
FelSiq committed Aug 21, 2020
2 parents 5f848e2 + b54f2df commit c8f5d4a
Showing 1 changed file with 74 additions and 60 deletions.
134 changes: 74 additions & 60 deletions pymfe/mfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import collections
import shutil
import time
import warnings

import texttable
import numpy as np
Expand Down Expand Up @@ -1027,7 +1028,7 @@ def fit(
Value used as ``select all`` for ``precomp_groups``.
suppress_warnings : :obj:`bool`, optional
If True, ignore all warnings invoked while fitting dataset.
If True, ignore all warnings invoked while fitting the dataset.
verbose : :obj:`int`, optional
Defines the level of verbosity for the fit method. If `1`, then
Expand Down Expand Up @@ -1058,49 +1059,56 @@ def fit(
If X or y (or both) is neither a :obj:`list` or a :obj:`np.ndarray`
object.
"""
if verbose >= 2:
print("Fitting data into model... ", end="")
with warnings.catch_warnings():
if suppress_warnings:
warnings.filterwarnings("ignore")

self.X, self.y = _internal.check_data(X, y)
if verbose >= 2:
print("Fitting data into model... ", end="")

if verbose >= 2:
print("Done.")
self.X, self.y = _internal.check_data(X, y)

rescale = _internal.process_generic_option(
value=rescale, group_name="rescale", allow_none=True
)
if verbose >= 2:
print("Done.")

self._fill_col_ind_by_type(cat_cols=cat_cols, check_bool=check_bool)
rescale = _internal.process_generic_option(
value=rescale, group_name="rescale", allow_none=True
)

if verbose >= 2:
print(
"Started data transformation process.",
" {} Encoding numerical data into discrete values... ".format(
_internal.VERBOSE_BLOCK_END_SYMBOL
),
sep="\n",
end="",
self._fill_col_ind_by_type(
cat_cols=cat_cols, check_bool=check_bool
)

data_cat = self._set_data_categoric(transform_num=transform_num)
if verbose >= 2:
print(
"Started data transformation process.",
" {} Encoding numerical data into discrete values... "
.format(_internal.VERBOSE_BLOCK_END_SYMBOL),
sep="\n",
end="",
)

if verbose >= 2:
print(
"Done.",
" {} Enconding categorical data into numerical values... "
.format(_internal.VERBOSE_BLOCK_END_SYMBOL),
sep="\n",
end="",
)
data_cat = self._set_data_categoric(transform_num=transform_num)

data_num = self._set_data_numeric(
transform_cat=transform_cat,
rescale=rescale,
rescale_args=rescale_args,
)
if verbose >= 2:
print(
"Done.",
" {} Enconding categorical data into numerical values... "
.format(_internal.VERBOSE_BLOCK_END_SYMBOL),
sep="\n",
end="",
)

if verbose >= 2:
print("Done.", "Finished data transformation process.", sep="\n")
data_num = self._set_data_numeric(
transform_cat=transform_cat,
rescale=rescale,
rescale_args=rescale_args,
)

if verbose >= 2:
print(
"Done.", "Finished data transformation process.", sep="\n"
)

# Custom arguments for metafeature extraction methods
self._custom_args_ft = {
Expand All @@ -1124,15 +1132,20 @@ def fit(

_time_start = time.time()

# Custom arguments from preprocessing methods
self._precomp_args_ft = _internal.process_precomp_groups(
precomp_groups=precomp_groups,
groups=self.groups,
wildcard=wildcard,
suppress_warnings=suppress_warnings,
verbose=verbose,
**{**self._custom_args_ft, **kwargs},
)
with warnings.catch_warnings():
if suppress_warnings:
warnings.filterwarnings("ignore")

# Custom arguments from preprocessing methods
self._precomp_args_ft = _internal.process_precomp_groups(
precomp_groups=precomp_groups,
groups=self.groups,
wildcard=wildcard,
suppress_warnings=suppress_warnings,
verbose=verbose,
**self._custom_args_ft,
**kwargs,
)

self.time_precomp = time.time() - _time_start

Expand Down Expand Up @@ -1187,10 +1200,7 @@ def extract(
(to be implemented).
suppress_warnings : :obj:`bool`, optional
If True, do not show warnings about unknown user custom parameters
for feature extraction and summary methods passed via kwargs. Note
that both feature extraction and summary methods may still raise
warnings by itself.
If True, do not show any warning while extracting meta-features.
kwargs:
Used to pass custom arguments for both feature-extraction and
Expand Down Expand Up @@ -1272,20 +1282,24 @@ def extract(

_time_start = time.time()

results = self._call_feature_methods(
verbose=verbose,
enable_parallel=enable_parallel,
suppress_warnings=suppress_warnings,
**kwargs,
) # type: t.Tuple[t.List, ...]
with warnings.catch_warnings():
if suppress_warnings:
warnings.filterwarnings("ignore")

_internal.post_processing(
results=results,
groups=self.groups,
suppress_warnings=suppress_warnings,
**self._postprocess_args_ft,
**kwargs,
)
results = self._call_feature_methods(
verbose=verbose,
enable_parallel=enable_parallel,
suppress_warnings=suppress_warnings,
**kwargs,
) # type: t.Tuple[t.List, ...]

_internal.post_processing(
results=results,
groups=self.groups,
suppress_warnings=suppress_warnings,
**self._postprocess_args_ft,
**kwargs,
)

self.time_extract = time.time() - _time_start
self.time_total = self.time_extract + self.time_precomp
Expand Down

0 comments on commit c8f5d4a

Please sign in to comment.