From 00994e922be77d686c303d3d6bc3a484478d95d7 Mon Sep 17 00:00:00 2001 From: Peter Szalai Date: Sun, 26 Mar 2017 19:51:10 +0200 Subject: [PATCH 1/9] getType fix --- python/pyspark/sql/types.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/python/pyspark/sql/types.py b/python/pyspark/sql/types.py index 26b54a7fb3709..04b28ec9ddb79 100644 --- a/python/pyspark/sql/types.py +++ b/python/pyspark/sql/types.py @@ -57,7 +57,25 @@ def __ne__(self, other): @classmethod def typeName(cls): - return cls.__name__[:-4].lower() + typeTypeNameMap = {"DataType": "data", + "NullType": "null", + "StringType": "string", + "BinaryType": "binary", + "BooleanType": "boolean", + "DateType": "Date", + "TimestampType": "timestamp", + "DecimalType": "decimal", + "DoubleType": "double", + "FloatType": "float", + "ByteType": "byte", + "IntegerType": "integer", + "LongType": "long", + "ShortType": "short", + "ArrayType": "array", + "MapType": "map", + "StructField": "struct", + "StructType": "struct"} + return typeTypeNameMap[cls.__name__] def simpleString(self): return self.typeName() From 933f3cb7f0b97f3bd79ea55bbd15dc27d0946c4b Mon Sep 17 00:00:00 2001 From: Peter Szalai Date: Sun, 26 Mar 2017 20:10:29 +0200 Subject: [PATCH 2/9] type --- python/pyspark/sql/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyspark/sql/types.py b/python/pyspark/sql/types.py index 04b28ec9ddb79..4e0758fd867bd 100644 --- a/python/pyspark/sql/types.py +++ b/python/pyspark/sql/types.py @@ -62,7 +62,7 @@ def typeName(cls): "StringType": "string", "BinaryType": "binary", "BooleanType": "boolean", - "DateType": "Date", + "DateType": "date", "TimestampType": "timestamp", "DecimalType": "decimal", "DoubleType": "double", From 0a1819296e30ebf2a4d62173d726526766ce2ca0 Mon Sep 17 00:00:00 2001 From: Peter Szalai Date: Sat, 13 May 2017 22:57:44 +0200 Subject: [PATCH 3/9] StructField's typeName raise TypeError --- python/pyspark/sql/types.py | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/python/pyspark/sql/types.py b/python/pyspark/sql/types.py index 4e0758fd867bd..9cb36a7b99dff 100644 --- a/python/pyspark/sql/types.py +++ b/python/pyspark/sql/types.py @@ -57,25 +57,7 @@ def __ne__(self, other): @classmethod def typeName(cls): - typeTypeNameMap = {"DataType": "data", - "NullType": "null", - "StringType": "string", - "BinaryType": "binary", - "BooleanType": "boolean", - "DateType": "date", - "TimestampType": "timestamp", - "DecimalType": "decimal", - "DoubleType": "double", - "FloatType": "float", - "ByteType": "byte", - "IntegerType": "integer", - "LongType": "long", - "ShortType": "short", - "ArrayType": "array", - "MapType": "map", - "StructField": "struct", - "StructType": "struct"} - return typeTypeNameMap[cls.__name__] + return cls.__name__[:-4].lower() def simpleString(self): return self.typeName() @@ -456,6 +438,9 @@ def toInternal(self, obj): def fromInternal(self, obj): return self.dataType.fromInternal(obj) + def typeName(self): + raise TypeError('StructField does not have typename') + class StructType(DataType): """Struct type, consisting of a list of :class:`StructField`. From 6bf11f027a5117b82936f88918e13e89993f2108 Mon Sep 17 00:00:00 2001 From: Peter Szalai Date: Sat, 20 May 2017 19:42:34 +0200 Subject: [PATCH 4/9] add test --- python/pyspark/sql/tests.py | 4 ++++ python/pyspark/sql/types.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/python/pyspark/sql/tests.py b/python/pyspark/sql/tests.py index b93b7ed192104..21517b4870a2d 100644 --- a/python/pyspark/sql/tests.py +++ b/python/pyspark/sql/tests.py @@ -188,6 +188,10 @@ def test_empty_row(self): row = Row() self.assertEqual(len(row), 0) + def test_struct_field_type_name(self): + struct_field = StructField() + self.assertRaises(typeError('StructField does not have typename. You can use self.dataType.simpleString() instead.'), struct_field.typeName) + class SQLTests(ReusedPySparkTestCase): diff --git a/python/pyspark/sql/types.py b/python/pyspark/sql/types.py index 9cb36a7b99dff..9acd9b0042269 100644 --- a/python/pyspark/sql/types.py +++ b/python/pyspark/sql/types.py @@ -439,7 +439,7 @@ def fromInternal(self, obj): return self.dataType.fromInternal(obj) def typeName(self): - raise TypeError('StructField does not have typename') + raise TypeError('StructField does not have typename. You can use self.dataType.simpleString() instead.') class StructType(DataType): From 8872e190b16b328205e0df569d5f5bc3af6c5610 Mon Sep 17 00:00:00 2001 From: Peter Szalai Date: Sun, 25 Jun 2017 23:01:45 +0200 Subject: [PATCH 5/9] fixing pep8 style issues --- python/pyspark/sql/tests.py | 5 ++++- python/pyspark/sql/types.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/python/pyspark/sql/tests.py b/python/pyspark/sql/tests.py index 21517b4870a2d..fc4599be8aabf 100644 --- a/python/pyspark/sql/tests.py +++ b/python/pyspark/sql/tests.py @@ -190,7 +190,10 @@ def test_empty_row(self): def test_struct_field_type_name(self): struct_field = StructField() - self.assertRaises(typeError('StructField does not have typename. You can use self.dataType.simpleString() instead.'), struct_field.typeName) + self.assertRaises(typeError( + "StructField does not have typename. \ + You can use self.dataType.simpleString() instead."), + struct_field.typeName) class SQLTests(ReusedPySparkTestCase): diff --git a/python/pyspark/sql/types.py b/python/pyspark/sql/types.py index 9acd9b0042269..25b6d2f48293f 100644 --- a/python/pyspark/sql/types.py +++ b/python/pyspark/sql/types.py @@ -439,7 +439,9 @@ def fromInternal(self, obj): return self.dataType.fromInternal(obj) def typeName(self): - raise TypeError('StructField does not have typename. You can use self.dataType.simpleString() instead.') + raise TypeError( + "StructField does not have typename. \ + You can use self.dataType.simpleString() instead.") class StructType(DataType): From a18436d290f7a924d1d46b9e0f14ba3ec86174c6 Mon Sep 17 00:00:00 2001 From: Peter Szalai Date: Thu, 7 Sep 2017 09:50:20 +0200 Subject: [PATCH 6/9] test failure fixed --- python/pyspark/sql/tests.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/python/pyspark/sql/tests.py b/python/pyspark/sql/tests.py index fc4599be8aabf..d6a9d68092981 100644 --- a/python/pyspark/sql/tests.py +++ b/python/pyspark/sql/tests.py @@ -189,11 +189,8 @@ def test_empty_row(self): self.assertEqual(len(row), 0) def test_struct_field_type_name(self): - struct_field = StructField() - self.assertRaises(typeError( - "StructField does not have typename. \ - You can use self.dataType.simpleString() instead."), - struct_field.typeName) + struct_field = StructField("a", IntegerType()) + self.assertRaises(TypeError, struct_field.typeName) class SQLTests(ReusedPySparkTestCase): From a45190160dba7f75ea26d18f2b16c703649dc541 Mon Sep 17 00:00:00 2001 From: Peter Szalai Date: Fri, 8 Sep 2017 13:24:33 +0200 Subject: [PATCH 7/9] improving error message --- python/pyspark/sql/types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/pyspark/sql/types.py b/python/pyspark/sql/types.py index 25b6d2f48293f..9bcefd68200a3 100644 --- a/python/pyspark/sql/types.py +++ b/python/pyspark/sql/types.py @@ -440,8 +440,8 @@ def fromInternal(self, obj): def typeName(self): raise TypeError( - "StructField does not have typename. \ - You can use self.dataType.simpleString() instead.") + "StructField does not have typeName." + "Use typeName on its type explicitly instead.") class StructType(DataType): From 98bac1272e79fb5114bbdf604ef0c5668136f4f9 Mon Sep 17 00:00:00 2001 From: Peter Szalai Date: Fri, 8 Sep 2017 14:38:49 +0200 Subject: [PATCH 8/9] adding space --- python/pyspark/sql/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyspark/sql/types.py b/python/pyspark/sql/types.py index 9bcefd68200a3..0140fd3603f5e 100644 --- a/python/pyspark/sql/types.py +++ b/python/pyspark/sql/types.py @@ -441,7 +441,7 @@ def fromInternal(self, obj): def typeName(self): raise TypeError( "StructField does not have typeName." - "Use typeName on its type explicitly instead.") + "Use typeName on its type explicitly instead. ") class StructType(DataType): From 28f142c13b7eeeb4f14b0fe06af423d737dd75e3 Mon Sep 17 00:00:00 2001 From: Peter Szalai Date: Sat, 9 Sep 2017 09:48:04 +0200 Subject: [PATCH 9/9] space at thr right place --- python/pyspark/sql/types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/pyspark/sql/types.py b/python/pyspark/sql/types.py index 0140fd3603f5e..d9206dd14ca2d 100644 --- a/python/pyspark/sql/types.py +++ b/python/pyspark/sql/types.py @@ -440,8 +440,8 @@ def fromInternal(self, obj): def typeName(self): raise TypeError( - "StructField does not have typeName." - "Use typeName on its type explicitly instead. ") + "StructField does not have typeName. " + "Use typeName on its type explicitly instead.") class StructType(DataType):