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
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
[GH90] add alias to u for impyute.ops.util
  • Loading branch information
Elton Law committed Oct 5, 2019
commit 5ae8b5095711866260cb7cfac195b41d43d29ec4
16 changes: 8 additions & 8 deletions impyute/ops/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from impyute.ops import BadOutputError
from impyute.ops import find_null
from impyute.ops.matrix import map_nd
from impyute.ops.util import *
import impyute.ops.util as u

## Hacky way to handle python2 not having `ModuleNotFoundError`
# pylint: disable=redefined-builtin, missing-docstring
Expand Down Expand Up @@ -57,7 +57,7 @@ def wrapper(*args, **kwargs):
args[0] = args[0].values

## function invokation
results = execute_fn_with_args_and_or_kwargs(fn, args, kwargs)
results = u.execute_fn_with_args_and_or_kwargs(fn, args, kwargs)

## cast the output back to a DataFrame.
if postprocess_fn is not None:
Expand All @@ -83,7 +83,7 @@ def wrapper(*args, **kwargs):
args[0] = args[0].copy()

## function invokation
return execute_fn_with_args_and_or_kwargs(fn, args, kwargs)
return u.execute_fn_with_args_and_or_kwargs(fn, args, kwargs)
return wrapper

def conform_output(fn):
Expand Down Expand Up @@ -114,15 +114,15 @@ def raise_error(arr, x_i, y_i):
## convert tuple to list so args can be modified
args = list(args)
# function that checks if the value is valid
valid_fn = kwargs.get("valid_fn", constantly(True))
valid_fn = kwargs.get("valid_fn", u.constantly(True))
# function that modifies the invalid value to something valid
coerce_fn = kwargs.get("coerce_fn", raise_error)

## function invokation
results = execute_fn_with_args_and_or_kwargs(fn, args, kwargs)
results = u.execute_fn_with_args_and_or_kwargs(fn, args, kwargs)

# check each value to see if it's valid
bool_arr = map_nd(complement(valid_fn), results)
bool_arr = map_nd(u.complement(valid_fn), results)
# get indices of invalid values
invalid_indices = np.argwhere(bool_arr)
# run the coerce fn on each invalid indice
Expand All @@ -140,7 +140,7 @@ def preprocess(fn):
entry point) since every other function assumes you're getting an np.array
as input
"""
return thread(
return u.thread(
fn, # function that's getting wrapped
add_inplace_option, # allow choosing reference/copy
conform_output, # allow enforcing of some spec on returned outputs
Expand Down Expand Up @@ -183,5 +183,5 @@ def wrapper(*args, **kwargs):
raise BadInputError("Data is not float.")
elif not _nan_exists(data):
raise BadInputError("No NaN's in given data")
return execute_fn_with_args_and_or_kwargs(fn, args, kwargs)
return u.execute_fn_with_args_and_or_kwargs(fn, args, kwargs)
return wrapper