gene-db commented on code in PR #52260:
URL: https://github.com/apache/spark/pull/52260#discussion_r2501587763
##########
python/pyspark/sql/tests/test_types.py:
##########
@@ -2348,6 +2348,22 @@ def test_variant_type(self):
with self.assertRaises(PySparkValueError, msg="Rows cannot be of type
VariantVal"):
self.spark.createDataFrame([VariantVal.parseJson("2")], "v
variant")
+ def test_variant_to_pandas(self):
+ import pandas as pd
+ import json
+
+ expected_values = [
+ ("str", '"%s"' % ("0123456789" * 10), "0123456789" * 10),
+ ("short_str", '"abc"', "abc"),
+ ]
+ json_str = "{%s}" % ",".join(['"%s": %s' % (t[0], t[1]) for t in
expected_values])
+ df = self.spark.createDataFrame([({"json": json_str})])
+ df_variant = df.select(F.parse_json(df.json).alias("v"))
+ pandas = df_variant.toPandas()
+ test_record = json.loads(pandas["v"].iloc[0].toJson())
+ self.assertIsInstance(pandas, pd.DataFrame)
+ self.assertEqual("abc", test_record["short_str"])
Review Comment:
Can we verify everything in `expected_values`? I thought that was what the
3rd entry was supposed to represent in `expected_values`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]