Skip to content

[SPARK-32686][PYTHON] Un-deprecate inferring DataFrame schema from list of dict #29510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions python/pyspark/sql/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,38 +359,31 @@ def range(self, start, end=None, step=1, numPartitions=None):

def _inferSchemaFromList(self, data, names=None):
"""
Infer schema from list of Row or tuple.
Infer schema from list of Row, dict, or tuple.

:param data: list of Row or tuple
:param data: list of Row, dict, or tuple
:param names: list of column names
:return: :class:`pyspark.sql.types.StructType`
"""
if not data:
raise ValueError("can not infer schema from empty dataset")
first = data[0]
if type(first) is dict:
warnings.warn("inferring schema from dict is deprecated,"
"please use pyspark.sql.Row instead")
schema = reduce(_merge_type, (_infer_schema(row, names) for row in data))
if _has_nulltype(schema):
raise ValueError("Some of types cannot be determined after inferring")
return schema

def _inferSchema(self, rdd, samplingRatio=None, names=None):
"""
Infer schema from an RDD of Row or tuple.
Infer schema from an RDD of Row, dict, or tuple.

:param rdd: an RDD of Row or tuple
:param rdd: an RDD of Row, dict, or tuple
:param samplingRatio: sampling ratio, or no sampling (default)
:return: :class:`pyspark.sql.types.StructType`
"""
first = rdd.first()
if not first:
raise ValueError("The first row in RDD is empty, "
"can not infer schema")
if type(first) is dict:
warnings.warn("Using RDD of dict to inferSchema is deprecated. "
"Use pyspark.sql.Row instead")

if samplingRatio is None:
schema = _infer_schema(first, names=names)
Expand Down