Skip to content

Commit

Permalink
Merge pull request #409 from mxlei01/decorator_fix_01
Browse files Browse the repository at this point in the history
Removed partial and debug option.
  • Loading branch information
Aylr committed Oct 21, 2017
2 parents 9d89f89 + 78e6065 commit c28b973
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ eliminated the need for .mdf fixtures on appveyor.
- validate_catalyst_prediction_sam_connection made much more robust with tests.
- Conda environment files cleaned up substantially, speeding up builds.
- Release preparation notes moved out of README and into a separate doc.
- Decorators for `supervised_model_trainer` is now simplified, and debug option is no longer an option.

### Fixed

Expand Down
25 changes: 2 additions & 23 deletions healthcareai/common/trainer_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from functools import partial, wraps


def trainer_output(func=None, *, debug=False):
def trainer_output(func):
"""
Trainer output decorator for functions that train models.
Expand All @@ -18,20 +18,11 @@ def trainer_output(func=None, *, debug=False):
Args:
func (function): Function to be applied with decorator.
debug (bool): Debug option true or false.
* (params): trainer_output arguments.
Returns:
trained_model|function: returns trained_model when called without a
function, or returns a callable when supplied with arguments.
trained_model: returns trained_model
"""

if func is None:
# This func is only None when extra arguments are supplied, return a
# callable instead, which will get run and goes to the def wrap. Handy
# way of using decorators with extra arguments.
return partial(trainer_output, debug=debug)

# Wrap around our function so that if debug is true, we can print out
# inputs and outputs. The @wraps decorator copies the parent function's
# attributes, such as __name__, and input parameters.
Expand All @@ -48,18 +39,6 @@ def wrap(self, *args, **kwargs):
self._advanced_trainer.model_type))
trained_model = func(self, *args, **kwargs)
trained_model.print_training_results()

# If debug is true, output the function name, default, argument, and
# returns.
if debug:
print("Function Name: {}, Function Defaults: {}, "
"Function Args: {} {}, Function Return: {}".format(
func.__name__,
inspect.signature(func),
args,
kwargs,
trained_model))

return trained_model

return wrap

0 comments on commit c28b973

Please sign in to comment.