Skip to content

Commit

Permalink
update doc style
Browse files Browse the repository at this point in the history
  • Loading branch information
gene-db committed Apr 5, 2024
1 parent 4f93a4e commit 9302887
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions python/pyspark/sql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1478,29 +1478,47 @@ def __eq__(self, other: Any) -> bool:
class VariantVal:
"""
A class to represent a Variant value in Python.
.. versionadded:: 4.0.0
Parameters
----------
value : bytes
The bytes representing the value component of the Variant.
metadata : bytes
The bytes representing the metadata component of the Variant.
Methods
-------
toPython()
Convert the VariantVal to a Python data structure.
Examples
--------
>>> df = spark.createDataFrame([ {'json': '''{ "a" : 1 }'''} ])
>>> v = df.select(parse_json(df.json).alias("var")).collect()[0].var
>>> v.toPython()
{'a': 1}
"""

def __init__(self, value: bytes, metadata: bytes):
self.value = value
self.metadata = metadata

def __str__(self) -> str:
return self.toString()
return VariantUtils.to_json(self.value, self.metadata)

def __repr__(self) -> str:
return "VariantVal(%s, %s)" % (self.value, self.metadata)

def toString(self) -> str:
"""
Convert the VariantVal to a string.
:return: a string representation of the Variant
"""
return VariantUtils.to_json(self.value, self.metadata)

def toPython(self) -> str:
def toPython(self) -> Any:
"""
Convert the VariantVal to a Python data structure.
:return: a Python object
Returns
-------
Any
A Python object that represents the Variant.
"""
return VariantUtils.to_python(self.value, self.metadata)

Expand Down

0 comments on commit 9302887

Please sign in to comment.