aboutsummaryrefslogtreecommitdiff
path: root/python/pyspark/ml/util.py
diff options
context:
space:
mode:
authorXiangrui Meng <meng@databricks.com>2015-02-15 20:29:26 -0800
committerXiangrui Meng <meng@databricks.com>2015-02-15 20:29:26 -0800
commitcd4a15366244657c4b7936abe5054754534366f2 (patch)
treefbee98a5031440c879705f2c7f9717b5d815c66e /python/pyspark/ml/util.py
parent836577b382695558f5c97d94ee725d0156ebfad2 (diff)
downloadspark-cd4a15366244657c4b7936abe5054754534366f2.tar.gz
spark-cd4a15366244657c4b7936abe5054754534366f2.tar.bz2
spark-cd4a15366244657c4b7936abe5054754534366f2.zip
[SPARK-5769] Set params in constructors and in setParams in Python ML pipelines
This PR allow Python users to set params in constructors and in setParams, where we use decorator `keyword_only` to force keyword arguments. The trade-off is discussed in the design doc of SPARK-4586. Generated doc: ![screen shot 2015-02-12 at 3 06 58 am](https://cloud.githubusercontent.com/assets/829644/6166491/9cfcd06a-b265-11e4-99ea-473d866634fc.png) CC: davies rxin Author: Xiangrui Meng <meng@databricks.com> Closes #4564 from mengxr/py-pipeline-kw and squashes the following commits: fedf720 [Xiangrui Meng] use toDF d565f2c [Xiangrui Meng] Merge remote-tracking branch 'apache/master' into py-pipeline-kw cbc15d3 [Xiangrui Meng] fix style 5032097 [Xiangrui Meng] update pipeline signature 950774e [Xiangrui Meng] simplify keyword_only and update constructor/setParams signatures fdde5fc [Xiangrui Meng] fix style c9384b8 [Xiangrui Meng] fix sphinx doc 8e59180 [Xiangrui Meng] add setParams and make constructors take params, where we force keyword args
Diffstat (limited to 'python/pyspark/ml/util.py')
-rw-r--r--python/pyspark/ml/util.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/python/pyspark/ml/util.py b/python/pyspark/ml/util.py
index b1caa84b63..81d3f0882b 100644
--- a/python/pyspark/ml/util.py
+++ b/python/pyspark/ml/util.py
@@ -15,6 +15,7 @@
# limitations under the License.
#
+from functools import wraps
import uuid
@@ -32,6 +33,20 @@ def inherit_doc(cls):
return cls
+def keyword_only(func):
+ """
+ A decorator that forces keyword arguments in the wrapped method
+ and saves actual input keyword arguments in `_input_kwargs`.
+ """
+ @wraps(func)
+ def wrapper(*args, **kwargs):
+ if len(args) > 1:
+ raise TypeError("Method %s forces keyword arguments." % func.__name__)
+ wrapper._input_kwargs = kwargs
+ return func(*args, **kwargs)
+ return wrapper
+
+
class Identifiable(object):
"""
Object with a unique ID.