@@ -350,7 +350,7 @@ def dtypes(self):
350350 @property
351351 def spark_type (self ):
352352 """ Returns the data type as defined by Spark, as a Spark DataType object."""
353- return self .schema . fields [ - 1 ]. dataType
353+ return self ._internal . spark_type_for ( self . _internal . column_index [ 0 ])
354354
355355 plot = CachedAccessor ("plot" , KoalasSeriesPlotMethods )
356356
@@ -798,10 +798,10 @@ def astype(self, dtype) -> 'Series':
798798 return self ._with_new_scol (self ._scol .cast (spark_type ))
799799
800800 def getField (self , name ):
801- if not isinstance (self .schema , StructType ):
802- raise AttributeError ("Not a struct: {}" .format (self .schema ))
801+ if not isinstance (self .spark_type , StructType ):
802+ raise AttributeError ("Not a struct: {}" .format (self .spark_type ))
803803 else :
804- fnames = self .schema .fieldNames ()
804+ fnames = self .spark_type .fieldNames ()
805805 if name not in fnames :
806806 raise AttributeError (
807807 "Field {} not found, possible values are {}" .format (name , ", " .join (fnames )))
@@ -811,11 +811,6 @@ def alias(self, name):
811811 """An alias for :meth:`Series.rename`."""
812812 return self .rename (name )
813813
814- @property
815- def schema (self ) -> StructType :
816- """Return the underlying Spark DataFrame's schema."""
817- return self .to_dataframe ()._sdf .schema
818-
819814 @property
820815 def shape (self ):
821816 """Return a tuple of the shape of the underlying data."""
@@ -4030,10 +4025,10 @@ def __repr__(self):
40304025 return pser .to_string (name = self .name , dtype = self .dtype )
40314026
40324027 def __dir__ (self ):
4033- if not isinstance (self .schema , StructType ):
4028+ if not isinstance (self .spark_type , StructType ):
40344029 fields = []
40354030 else :
4036- fields = [f for f in self .schema .fieldNames () if ' ' not in f ]
4031+ fields = [f for f in self .spark_type .fieldNames () if ' ' not in f ]
40374032 return super (Series , self ).__dir__ () + fields
40384033
40394034 def __iter__ (self ):
0 commit comments