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(python): load_as_version with datetime object with no timezone specified #2429

Merged
merged 1 commit into from
Apr 21, 2024
Merged
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
8 changes: 6 additions & 2 deletions python/deltalake/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import operator
import warnings
from dataclasses import dataclass
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from enum import Enum
from functools import reduce
from pathlib import Path
Expand Down Expand Up @@ -607,6 +607,7 @@ def load_as_version(self, version: Union[int, str, datetime]) -> None:
"""
Load/time travel a DeltaTable to a specified version number, or a timestamp version of the table. If a
string is passed then the argument should be an RFC 3339 and ISO 8601 date and time string format.
If a datetime object without a timezone is passed, the UTC timezone will be assumed.

Args:
version: the identifier of the version of the DeltaTable to load
Expand All @@ -620,7 +621,8 @@ def load_as_version(self, version: Union[int, str, datetime]) -> None:

**Use a datetime object**
```
dt.load_as_version(datetime(2023,1,1))
dt.load_as_version(datetime(2023, 1, 1))
dt.load_as_version(datetime(2023, 1, 1, tzinfo=timezone.utc))
```

**Use a datetime in string format**
Expand All @@ -633,6 +635,8 @@ def load_as_version(self, version: Union[int, str, datetime]) -> None:
if isinstance(version, int):
self._table.load_version(version)
elif isinstance(version, datetime):
if version.tzinfo is None:
version = version.astimezone(timezone.utc)
self._table.load_with_datetime(version.isoformat())
elif isinstance(version, str):
self._table.load_with_datetime(version)
Expand Down
Loading