Github user tomasatdatabricks commented on a diff in the pull request: https://github.com/apache/spark/pull/20168#discussion_r160496086 --- Diff: python/pyspark/ml/image.py --- @@ -71,9 +88,30 @@ def ocvTypes(self): """ if self._ocvTypes is None: - ctx = SparkContext._active_spark_context - self._ocvTypes = dict(ctx._jvm.org.apache.spark.ml.image.ImageSchema.javaOcvTypes()) - return self._ocvTypes + ctx = SparkContext.getOrCreate() + ocvTypeList = ctx._jvm.org.apache.spark.ml.image.ImageSchema.javaOcvTypes() + self._ocvTypes = [self._OcvType(name=x.name(), + mode=x.mode(), + nChannels=x.nChannels(), + dataType=x.dataType(), + nptype=self._ocvToNumpyMap[x.dataType()]) + for x in ocvTypeList] + return self._ocvTypes[:] + + def ocvTypeByName(self, name): + if self._ocvTypesByName is None: + self._ocvTypesByName = {x.name: x for x in self.ocvTypes} + if name not in self._ocvTypesByName: + raise ValueError( + "Can not find matching OpenCvFormat for type = '%s'; supported formats are = %s" % + (name, str( + self._ocvTypesByName.keys()))) + return self._ocvTypesByName[name] + + def ocvTypeByMode(self, mode): --- End diff -- It is not consistent because python can not overload methods based on type but I can rename the Scala side to match python. It does not make a big difference in this case.
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org