Skip to content
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

fix: reorder encode_partition_value() checks and add tests #1733

Merged
merged 3 commits into from
Oct 17, 2023
Merged
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
4 changes: 2 additions & 2 deletions python/deltalake/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def encode_partition_value(val: Any) -> str:
return val
elif isinstance(val, (int, float)):
return str(val)
elif isinstance(val, date):
return val.isoformat()
elif isinstance(val, datetime):
return val.isoformat(sep=" ")
elif isinstance(val, date):
return val.isoformat()
elif isinstance(val, bytes):
return val.decode("unicode_escape", "backslashreplace")
else:
Expand Down
34 changes: 33 additions & 1 deletion python/tests/test_table_read.py
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for thoroughly testing this 🙌

Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import os
from datetime import datetime
from datetime import date, datetime
from pathlib import Path
from threading import Barrier, Thread
from types import SimpleNamespace
from typing import Any
from unittest.mock import Mock

from packaging import version

from deltalake._util import encode_partition_value
from deltalake.exceptions import DeltaProtocolError
from deltalake.table import ProtocolVersions
from deltalake.writer import write_deltalake
Expand Down Expand Up @@ -695,3 +697,33 @@ def test_issue_1653_filter_bool_partition(tmp_path: Path):
)
== 1
)


@pytest.mark.parametrize(
"input_value, expected",
[
(True, "true"),
(False, "false"),
(1, "1"),
(1.5, "1.5"),
("string", "string"),
(date(2023, 10, 17), "2023-10-17"),
(datetime(2023, 10, 17, 12, 34, 56), "2023-10-17 12:34:56"),
(b"bytes", "bytes"),
([True, False], ["true", "false"]),
([1, 2], ["1", "2"]),
([1.5, 2.5], ["1.5", "2.5"]),
(["a", "b"], ["a", "b"]),
([date(2023, 10, 17), date(2023, 10, 18)], ["2023-10-17", "2023-10-18"]),
(
[datetime(2023, 10, 17, 12, 34, 56), datetime(2023, 10, 18, 12, 34, 56)],
["2023-10-17 12:34:56", "2023-10-18 12:34:56"],
),
([b"bytes", b"testbytes"], ["bytes", "testbytes"]),
],
)
def test_encode_partition_value(input_value: Any, expected: str) -> None:
if isinstance(input_value, list):
assert [encode_partition_value(val) for val in input_value] == expected
else:
assert encode_partition_value(input_value) == expected
Loading