You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by gu...@apache.org on 2023/08/03 03:05:13 UTC
[spark] branch master updated: [SPARK-44643][SQL][PYTHON] Fix Row.__repr__ for the case the field is empty Row
This is an automated email from the ASF dual-hosted git repository.
gurwls223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 8a847181172 [SPARK-44643][SQL][PYTHON] Fix Row.__repr__ for the case the field is empty Row
8a847181172 is described below
commit 8a8471811727cd4a49696e68713d459417ebca73
Author: Takuya UESHIN <ue...@databricks.com>
AuthorDate: Thu Aug 3 12:05:02 2023 +0900
[SPARK-44643][SQL][PYTHON] Fix Row.__repr__ for the case the field is empty Row
### What changes were proposed in this pull request?
Fix `Row.__repr__` for the case the field is empty `Row`.
```py
>>> repr(Row(Row()))
'<Row(<Row()>)>'
```
### Why are the changes needed?
`Row.__repr__` is broken when it contains an empty `Row`:
```py
>>> repr(Row(Row()))
Traceback (most recent call last):
...
TypeError: not enough arguments for format string
```
### Does this PR introduce _any_ user-facing change?
`Row` that contains an empty `Row` will be shown in the REPL.
### How was this patch tested?
Added the related test.
Closes #42303 from ueshin/issues/SPARK-44643/repr_row.
Authored-by: Takuya UESHIN <ue...@databricks.com>
Signed-off-by: Hyukjin Kwon <gu...@apache.org>
---
python/pyspark/sql/tests/test_types.py | 9 +++++++++
python/pyspark/sql/types.py | 2 +-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/python/pyspark/sql/tests/test_types.py b/python/pyspark/sql/tests/test_types.py
index 083aa151d0d..7cb13693a0d 100644
--- a/python/pyspark/sql/tests/test_types.py
+++ b/python/pyspark/sql/tests/test_types.py
@@ -1323,6 +1323,15 @@ class DataTypeTests(unittest.TestCase):
# test __repr__ with unicode values
self.assertEqual(repr(Row("数", "量")), "<Row('数', '量')>")
+ # SPARK-44643: test __repr__ with empty Row
+ def test_row_repr_with_empty_row(self):
+ self.assertEqual(repr(Row(a=Row())), "Row(a=<Row()>)")
+ self.assertEqual(repr(Row(Row())), "<Row(<Row()>)>")
+
+ EmptyRow = Row()
+ self.assertEqual(repr(Row(a=EmptyRow())), "Row(a=Row())")
+ self.assertEqual(repr(Row(EmptyRow())), "<Row(Row())>")
+
def test_empty_row(self):
row = Row()
self.assertEqual(len(row), 0)
diff --git a/python/pyspark/sql/types.py b/python/pyspark/sql/types.py
index db615d339b5..092fa43b1d2 100644
--- a/python/pyspark/sql/types.py
+++ b/python/pyspark/sql/types.py
@@ -2402,7 +2402,7 @@ class Row(tuple):
"%s=%r" % (k, v) for k, v in zip(self.__fields__, tuple(self))
)
else:
- return "<Row(%s)>" % ", ".join("%r" % field for field in self)
+ return "<Row(%s)>" % ", ".join(repr(field) for field in self)
class DateConverter:
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org