@@ -562,8 +562,8 @@ def _infer_type(obj):
562562 else :
563563 try :
564564 return _infer_schema (obj )
565- except ValueError :
566- raise ValueError ("not supported type: %s" % type (obj ))
565+ except TypeError :
566+ raise TypeError ("not supported type: %s" % type (obj ))
567567
568568
569569def _infer_schema (row ):
@@ -584,7 +584,7 @@ def _infer_schema(row):
584584 items = sorted (row .__dict__ .items ())
585585
586586 else :
587- raise ValueError ("Can not infer schema for type: %s" % type (row ))
587+ raise TypeError ("Can not infer schema for type: %s" % type (row ))
588588
589589 fields = [StructField (k , _infer_type (v ), True ) for k , v in items ]
590590 return StructType (fields )
@@ -696,7 +696,7 @@ def _merge_type(a, b):
696696 return a
697697 elif type (a ) is not type (b ):
698698 # TODO: type cast (such as int -> long)
699- raise TypeError ("Can not merge type %s and %s" % (a , b ))
699+ raise TypeError ("Can not merge type %s and %s" % (type ( a ), type ( b ) ))
700700
701701 # same type
702702 if isinstance (a , StructType ):
@@ -773,7 +773,7 @@ def convert_struct(obj):
773773 elif hasattr (obj , "__dict__" ): # object
774774 d = obj .__dict__
775775 else :
776- raise ValueError ("Unexpected obj: %s" % obj )
776+ raise TypeError ("Unexpected obj type : %s" % type ( obj ) )
777777
778778 if convert_fields :
779779 return tuple ([conv (d .get (name )) for name , conv in zip (names , converters )])
@@ -912,7 +912,7 @@ def _infer_schema_type(obj, dataType):
912912 return StructType (fields )
913913
914914 else :
915- raise ValueError ("Unexpected dataType: %s" % dataType )
915+ raise TypeError ("Unexpected dataType: %s" % type ( dataType ) )
916916
917917
918918_acceptable_types = {
0 commit comments