Skip to content

Commit aed3ecb

Browse files
committed
Remove Series.schema.
1 parent b161428 commit aed3ecb

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed

databricks/koalas/indexing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def raiseNotImplemented(description):
392392
stop = rows_sel.stop
393393

394394
index_column = self._kdf.index.to_series()
395-
index_data_type = index_column.schema[0].dataType
395+
index_data_type = index_column.spark_type
396396
cond = []
397397
if start is not None:
398398
cond.append(index_column._scol >= F.lit(start).cast(index_data_type))
@@ -414,7 +414,7 @@ def raiseNotImplemented(description):
414414
sdf = sdf.where(F.lit(False))
415415
elif len(self._kdf._internal.index_columns) == 1:
416416
index_column = self._kdf.index.to_series()
417-
index_data_type = index_column.schema[0].dataType
417+
index_data_type = index_column.spark_type
418418
if len(rows_sel) == 1:
419419
sdf = sdf.where(
420420
index_column._scol == F.lit(rows_sel[0]).cast(index_data_type))

databricks/koalas/internal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def scol_for(self, column_name_or_index: Union[str, Tuple[str, ...]]) -> spark.C
536536

537537
def spark_type_for(self, column_name_or_index: Union[str, Tuple[str, ...]]) -> DataType:
538538
""" Return DataType for the given column name or index. """
539-
return self._sdf.schema[self.column_name_for(column_name_or_index)].dataType
539+
return self._sdf.select(self.scol_for(column_name_or_index)).schema[0].dataType
540540

541541
@property
542542
def sdf(self) -> spark.DataFrame:

databricks/koalas/series.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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):

docs/source/reference/series.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Attributes
2626
Series.dtype
2727
Series.dtypes
2828
Series.name
29-
Series.schema
29+
Series.spark_type
3030
Series.shape
3131
Series.size
3232
Series.empty

0 commit comments

Comments
 (0)