Github user tomasatdatabricks commented on a diff in the pull request:
https://github.com/apache/spark/pull/20168#discussion_r161334810
--- Diff: python/pyspark/ml/tests.py ---
@@ -1843,6 +1844,27 @@ def tearDown(self):
class ImageReaderTest(SparkSessionTestCase):
+ def test_ocv_types(self):
+ ocvList = ImageSchema.ocvTypes
+ self.assertEqual("Undefined", ocvList[0].name)
+ self.assertEqual(-1, ocvList[0].mode)
+ self.assertEqual("N/A", ocvList[0].dataType)
+ for x in ocvList:
+ self.assertEqual(x, ImageSchema.ocvTypeByName(x.name))
+ self.assertEqual(x, ImageSchema.ocvTypeByMode(x.mode))
+
+ def test_conversions(self):
+ s = np.random.RandomState(seed=987)
+ ary_src = s.rand(4, 10, 10)
+ for ocvType in ImageSchema.ocvTypes:
+ if ocvType.name == 'Undefined':
+ continue
+ npary0 = ary_src[...,
0:ocvType.nChannels].astype(ocvType.nptype)
+ img = ImageSchema.toImage(npary0)
+ self.assertEqual(ocvType, ImageSchema.ocvTypeByMode(img.mode))
+ npary1 = ImageSchema.toNDArray(img)
+ np.testing.assert_array_equal(npary0, npary1)
--- End diff --
good point, I'll add the test.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]