Github user MrBago commented on a diff in the pull request:
https://github.com/apache/spark/pull/20168#discussion_r160294154
--- Diff: python/pyspark/ml/image.py ---
@@ -150,29 +194,27 @@ def toImage(self, array, origin=""):
"array argument should be numpy.ndarray; however, it got
[%s]." % type(array))
if array.ndim != 3:
- raise ValueError("Invalid array shape")
+ raise ValueError("Invalid array shape %s" % str(array.shape))
height, width, nChannels = array.shape
- ocvTypes = ImageSchema.ocvTypes
- if nChannels == 1:
- mode = ocvTypes["CV_8UC1"]
- elif nChannels == 3:
- mode = ocvTypes["CV_8UC3"]
- elif nChannels == 4:
- mode = ocvTypes["CV_8UC4"]
- else:
- raise ValueError("Invalid number of channels")
+ dtype = array.dtype
+ if dtype not in self._numpyToOcvMap:
+ raise ValueError(
+ "Unsupported array data type '%s', currently only
supported formats are %s" %
+ (str(array.dtype), str(self._numpyToOcvMap.keys())))
--- End diff --
"%s" will call `__str__` automatically so you don't need to wrap in `str`.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]