Github user imatiach-msft commented on a diff in the pull request:
https://github.com/apache/spark/pull/20168#discussion_r160260468
--- Diff: python/pyspark/ml/tests.py ---
@@ -1843,6 +1844,28 @@ 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):
+ ary_src = [[[1e7*random.random() for z in range(4)] for y in
range(10)] for x in range(10)]
+ for ocvType in ImageSchema.ocvTypes:
+ if ocvType.name == 'Undefined':
+ continue
+ x = [[ary_src[i][j][0:ocvType.nChannels]
+ for j in range(len(ary_src[0]))] for i in
range(len(ary_src))]
+ npary0 = np.array(x).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)
+
def test_read_images(self):
data_path = 'data/mllib/images/kittens'
--- End diff --
not necessary for this PR, but it would be nice to add images with the new
types to verify they can be read in with the new changes
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]