From 25d74513a1f145453f1d8b471a8109c42d0ee0ae Mon Sep 17 00:00:00 2001 From: Xiangrui Meng Date: Mon, 4 May 2015 23:11:34 -0700 Subject: [PATCH] fix tests in python 3 --- python/pyspark/ml/evaluation.py | 11 +++++------ python/pyspark/sql/_types.py | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/python/pyspark/ml/evaluation.py b/python/pyspark/ml/evaluation.py index ef8a1b65d72ba..02020ebff94c2 100644 --- a/python/pyspark/ml/evaluation.py +++ b/python/pyspark/ml/evaluation.py @@ -31,11 +31,10 @@ class BinaryClassificationEvaluator(JavaEvaluator, HasLabelCol, HasRawPrediction columns: rawPrediction and label. >>> from pyspark.mllib.linalg import Vectors - >>> scoreAndLabels = sc.parallelize([ - ... (0.1, 0.0), (0.1, 1.0), (0.4, 0.0), (0.6, 0.0), (0.6, 1.0), (0.6, 1.0), (0.8, 1.0)]) - >>> rawPredictionAndLabels = scoreAndLabels.map( - ... lambda x: (Vectors.dense([1.0 - x[0], x[0]]), x[1])) - >>> dataset = rawPredictionAndLabels.toDF(["raw", "label"]) + >>> scoreAndLabels = map(lambda x: (Vectors.dense([1.0 - x[0], x[0]]), x[1]), + ... [(0.1, 0.0), (0.1, 1.0), (0.4, 0.0), (0.6, 0.0), (0.6, 1.0), (0.6, 1.0), (0.8, 1.0)]) + >>> dataset = sqlContext.createDataFrame(scoreAndLabels, ["raw", "label"]) + ... >>> evaluator = BinaryClassificationEvaluator(rawPredictionCol="raw") >>> evaluator.evaluate(dataset) 0.70... @@ -97,7 +96,7 @@ def setParams(self, rawPredictionCol="rawPrediction", labelCol="label", globs = globals().copy() # The small batch size here ensures that we see multiple batches, # even in these small test examples: - sc = SparkContext("local[2]", "ml.feature tests") + sc = SparkContext("local[2]", "ml.evaluation tests") sqlContext = SQLContext(sc) globs['sc'] = sc globs['sqlContext'] = sqlContext diff --git a/python/pyspark/sql/_types.py b/python/pyspark/sql/_types.py index 95fb91ad43457..fd98e116d2cf1 100644 --- a/python/pyspark/sql/_types.py +++ b/python/pyspark/sql/_types.py @@ -652,7 +652,7 @@ def _python_to_sql_converter(dataType): if isinstance(dataType, StructType): names, types = zip(*[(f.name, f.dataType) for f in dataType.fields]) - converters = map(_python_to_sql_converter, types) + converters = [_python_to_sql_converter(t) for t in types] def converter(obj): if isinstance(obj, dict):