Github user MrBago commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20168#discussion_r160502167
  
    --- 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 --
    
    I think we could make either API work for both languages but it's a bit 
unnatural. There's a tradeoff between doing the most natural and appropriate 
thing in each language and having matching APIs, Spark has chosen to prefer 
making the APIs match so let's do our best to do that.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to