Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion python/pyspark/sql/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ def createDataFrame( # type: ignore[misc]
----------
data : :class:`RDD` or iterable
an RDD of any kind of SQL data representation (:class:`Row`,
:class:`tuple`, ``int``, ``boolean``, etc.), or :class:`list`,
:class:`tuple`, ``int``, ``boolean``, ``dict``, etc.), or :class:`list`,
:class:`pandas.DataFrame` or :class:`numpy.ndarray`.
schema : :class:`pyspark.sql.types.DataType`, str or list, optional
a :class:`pyspark.sql.types.DataType` or a datatype string or a list of
Expand Down
12 changes: 12 additions & 0 deletions python/pyspark/sql/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import pickle
import sys
import unittest
from dataclasses import dataclass, asdict

from pyspark.sql import Row
from pyspark.sql import functions as F
Expand Down Expand Up @@ -412,6 +413,17 @@ def test_create_dataframe_from_dict_respects_schema(self):
df = self.spark.createDataFrame([{"a": 1}], ["b"])
self.assertEqual(df.columns, ["b"])

def test_create_dataframe_from_dataclasses(self):
@dataclass
class User:
name: str
age: int
is_active: bool

user = User(name="John", age=30, is_active=True)
r = self.spark.createDataFrame([user]).first()
self.assertEqual(asdict(user), r.asDict())

def test_negative_decimal(self):
try:
self.spark.sql("set spark.sql.legacy.allowNegativeScaleOfDecimal=true")
Expand Down