Skip to content

Commit

Permalink
Merge pull request #94 from ealcobaca/precomp-lin-alg-err
Browse files Browse the repository at this point in the history
Now catching 'LinAlgErrors' in '.fit' method
  • Loading branch information
ealcobaca committed Jul 2, 2020
2 parents 45530ec + 69b729f commit 886c48d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
32 changes: 20 additions & 12 deletions pymfe/_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@

POSTPROCESS_PREFIX = "postprocess_"

TypeMtdTuple = t.Tuple[str, t.Callable[[], t.Any]]
TypeMtdTuple = t.Tuple[str, t.Callable[..., t.Any]]
"""Type annotation which describes the a metafeature method tuple."""

TypeExtMtdTuple = t.Tuple[str, t.Callable[[], t.Any],
TypeExtMtdTuple = t.Tuple[str, t.Callable[..., t.Any],
t.Tuple[str, ...], t.Tuple[str, ...]]
"""Type annotation which extends TypeMtdTuple with extra fields."""

Expand Down Expand Up @@ -205,6 +205,17 @@
}
"""'.extract_from_model' supported types and correspoding parameters."""

_EXCEPTIONS = (
ValueError,
TypeError,
MemoryError,
ZeroDivisionError,
AttributeError,
np.linalg.LinAlgError,
OverflowError,
)
"""Common exceptions of metafeature extraction."""


def warning_format(message: str,
category: t.Type[Warning],
Expand Down Expand Up @@ -426,10 +437,10 @@ def _get_all_prefixed_mtds(

if update_groups_by:
group_mtds_names = {
remove_prefix(mtd_name, prefix=MTF_PREFIX)
remove_prefix(mtd_pack[0], prefix=MTF_PREFIX)
if not prefix_removal
else mtd_name
for mtd_name, _ in group_mtds
else mtd_pack[0]
for mtd_pack in group_mtds
}

if not update_groups_by.isdisjoint(group_mtds_names):
Expand Down Expand Up @@ -535,7 +546,7 @@ def summarize(
try:
metafeature = callable_sum(features, **callable_args)

except (TypeError, ValueError, ZeroDivisionError, MemoryError):
except _EXCEPTIONS:
metafeature = np.nan

return metafeature
Expand Down Expand Up @@ -581,8 +592,7 @@ def get_feat_value(
try:
features = mtd_callable(**mtd_args)

except (TypeError, ValueError, ZeroDivisionError,
MemoryError, np.linalg.LinAlgError) as type_e:
except _EXCEPTIONS as type_e:
is_array = array_is_returned(mtd_callable)

if not suppress_warnings:
Expand Down Expand Up @@ -1207,8 +1217,7 @@ def process_precomp_groups(
try:
new_precomp_vals = precomp_mtd_callable(**kwargs) # type: ignore

except (AttributeError, TypeError,
ValueError, MemoryError) as type_err:
except _EXCEPTIONS as type_err:
new_precomp_vals = {}

if not suppress_warnings:
Expand Down Expand Up @@ -1768,8 +1777,7 @@ def post_processing(
for res_list_old, res_list_new in zip(results, new_results):
res_list_old += res_list_new

except (AttributeError, TypeError,
ValueError, MemoryError) as type_err:
except _EXCEPTIONS as type_err:
if not suppress_warnings:
warnings.warn("Something went wrong while "
"postprocessing '{0}'. Will ignore "
Expand Down
7 changes: 3 additions & 4 deletions pymfe/mfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1841,22 +1841,21 @@ def metafeature_description(
if not isinstance(print_table, bool):
raise TypeError("The parameter print_table should be bool.")

mtf_names = [] # type: t.List[str]
mtf_desc = [["Group", "Meta-feature name", "Description"]]
if include_references:
mtf_desc[0].append("Reference")

for group in groups.union(deps):
class_ind = _internal.VALID_GROUPS.index(group)

mtf_names = ( # type: ignore
_internal.get_prefixed_mtds_from_class( # type: ignore
mtf_names = ( # tipe: t.Collection[t.Tuple[str, t.Callable]]
_internal.get_prefixed_mtds_from_class(
class_obj=_internal.VALID_MFECLASSES[class_ind],
prefix=_internal.MTF_PREFIX,
only_name=False,
prefix_removal=True))

for name, method in mtf_names:
for name, method in mtf_names: # type: ignore
ini_desc, ref_desc = MFE._parse_description(
str(method.__doc__), include_references)
mtf_desc_line = [group, name, ini_desc]
Expand Down

0 comments on commit 886c48d

Please sign in to comment.