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
9 changes: 7 additions & 2 deletions python/pyspark/pandas/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,14 @@ def read_delta(
Path to the Delta Lake table.
version : string, optional
Specifies the table version (based on Delta's internal transaction version) to read from,
using Delta's time travel feature. This sets Delta's 'versionAsOf' option.
using Delta's time travel feature. This sets Delta's 'versionAsOf' option. Note that
this paramter and `timestamp` paramter cannot be used together, otherwise it will raise a
`ValueError`.
timestamp : string, optional
Specifies the table version (based on timestamp) to read from,
using Delta's time travel feature. This must be a valid date or timestamp string in Spark,
and sets Delta's 'timestampAsOf' option.
and sets Delta's 'timestampAsOf' option. Note that this paramter and `version` paramter
cannot be used together, otherwise it will raise a `ValueError`.
index_col : str or list of str, optional, default: None
Index column of table in Spark.
options
Expand Down Expand Up @@ -562,6 +565,8 @@ def read_delta(
3 13
4 14
"""
if version is not None and timestamp is not None:
raise ValueError("version and timestamp cannot be used together.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about the document?

Copy link
Member Author

@Yikun Yikun Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the doc for version and timestamp

if "options" in options and isinstance(options.get("options"), dict) and len(options) == 1:
options = options.get("options") # type: ignore

Expand Down
9 changes: 8 additions & 1 deletion python/pyspark/pandas/tests/test_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import pandas as pd

from pyspark import pandas as ps
from pyspark.pandas.namespace import _get_index_map
from pyspark.pandas.namespace import _get_index_map, read_delta
from pyspark.pandas.utils import spark_column_equals
from pyspark.testing.pandasutils import PandasOnSparkTestCase
from pyspark.testing.sqlutils import SQLTestUtils
Expand Down Expand Up @@ -329,6 +329,13 @@ def check(actual, expected):

self.assertRaises(KeyError, lambda: _get_index_map(sdf, ["year", "hour"]))

def test_read_delta_with_wrong_input(self):
self.assertRaisesRegex(
ValueError,
"version and timestamp cannot be used together",
lambda: read_delta("fake_path", version="0", timestamp="2021-06-22"),
)


if __name__ == "__main__":
import unittest
Expand Down