Skip to content

[GH-90] impossible value handling #91

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

Merged
merged 19 commits into from
Oct 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[GH-90] move var arg execute into util namespace
  • Loading branch information
Elton Law committed Sep 29, 2019
commit 34a3b2281c622452b638851fe9fa0cc1707aa1dc
12 changes: 12 additions & 0 deletions impyute/ops/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
""" Random utility functions """
from functools import wraps

__all__ = [
"constantly", "complement", "identity", "thread",
"execute_fn_with_args_and_or_kwargs"
]

def thread(arg, *fns):
if len(fns) > 0:
return thread(fns[0](arg), *fns[1:])
Expand All @@ -24,3 +29,10 @@ def complement(fn):
def wrapper(*args, **kwargs):
return not fn(*args, **kwargs)
return wrapper

def execute_fn_with_args_and_or_kwargs(fn, args, kwargs):
""" If args + kwargs aren't accepted only args are passed in"""
try:
return fn(*args, **kwargs)
except TypeError:
return fn(*args)
12 changes: 3 additions & 9 deletions impyute/ops/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"""
from functools import wraps
import numpy as np
from impyute.ops import BadInputError, BadOutputError
from impyute.ops import BadInputError
from impyute.ops import BadOutputError
from impyute.ops import find_null
from impyute.ops.util import identity, constantly, complement, thread
from impyute.ops.matrix import map_nd
from impyute.ops.util import *

## Hacky way to handle python2 not having `ModuleNotFoundError`
# pylint: disable=redefined-builtin, missing-docstring
Expand All @@ -21,13 +22,6 @@ class ModuleNotFoundError(Exception):
pass
# pylint: enable=redefined-builtin, missing-docstring

def execute_fn_with_args_and_or_kwargs(fn, args, kwargs):
""" If args + kwargs aren't accepted only args are passed in"""
try:
return fn(*args, **kwargs)
except TypeError:
return fn(*args)

def get_pandas_df():
""" Gets pandas DataFrame if we can import it """
try:
Expand Down