Github user holdenk commented on a diff in the pull request:
https://github.com/apache/spark/pull/18444#discussion_r125171058
--- Diff: python/pyspark/sql/tests.py ---
@@ -2250,6 +2256,67 @@ def test_BinaryType_serialization(self):
df = self.spark.createDataFrame(data, schema=schema)
df.collect()
+ # test for SPARK-16542
+ def test_array_types(self):
+ # This test need to make sure that the Scala type selected is at
least
+ # as large as the python's types. This is necessary because
python's
+ # array types depend on C implementation on the machine. Therefore
there
+ # is no machine independent correspondence between python's array
types
+ # and Scala types.
+ # See: https://docs.python.org/2/library/array.html
+
+ def assertCollectSuccess(typecode, value):
+ a = array.array(typecode, [value])
+ row = Row(myarray=a)
+ df = self.spark.createDataFrame([row])
+ self.assertEqual(df.collect()[0]["myarray"][0], value)
+
+ supported_types = []
+
+ # test string types
+ if sys.version < "4":
+ supported_types += ['u']
+ assertCollectSuccess('u', "a")
+ if sys.version < "3":
+ supported_types += ['c']
+ assertCollectSuccess('c', "a")
+
+ # test float and double, assuming IEEE 754 floating-point format
+ supported_types += ['f', 'd']
+ assertCollectSuccess('f', ctypes.c_float(1e+38).value)
+ assertCollectSuccess('f', ctypes.c_float(1e-38).value)
+ assertCollectSuccess('f', ctypes.c_float(1.123456).value)
+ assertCollectSuccess('d', ctypes.c_double(1e+308).value)
+ assertCollectSuccess('d', ctypes.c_double(1e+308).value)
+ assertCollectSuccess('d', ctypes.c_double(1.123456789012345).value)
+
+ # test int types
+ supported_int =
list(set(_array_int_typecode_ctype_mappings.keys()).
+
intersection(set(_array_type_mappings.keys())))
+ supported_types += supported_int
+ for i in supported_int:
+ ctype = _array_int_typecode_ctype_mappings[i]
+ if i.isupper():
--- End diff --
In the code that makes the mapping you have a comment about isupper being
unsigned, for Scala SQL devs who maybe have to debug this in the future, I'd
duplicate this comment here.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]