Skip to content

[SPARK-48695][PYTHON] TimestampNTZType.fromInternal not use the deprecated methods #47068

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

Closed
wants to merge 3 commits into from

Conversation

zhengruifeng
Copy link
Contributor

What changes were proposed in this pull request?

TimestampNTZType.fromInternal not use the deprecated methods

Why are the changes needed?

In [2]: ts = 111111111111

In [3]: datetime.datetime.utcfromtimestamp(ts // 1000000).replace(
   ...:                 microsecond=ts % 1000000
   ...:             )
<ipython-input-3-166450e5ec26>:1: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
  datetime.datetime.utcfromtimestamp(ts // 1000000).replace(
Out[3]: datetime.datetime(1970, 1, 2, 6, 51, 51, 111111)

Does this PR introduce any user-facing change?

No

How was this patch tested?

new tests

Was this patch authored or co-authored using generative AI tooling?

No

@@ -434,8 +434,8 @@ def toInternal(self, dt: datetime.datetime) -> int:
def fromInternal(self, ts: int) -> datetime.datetime:
if ts is not None:
# using int to avoid precision loss in float
return datetime.datetime.utcfromtimestamp(ts // 1000000).replace(
microsecond=ts % 1000000
return datetime.datetime.fromtimestamp(ts // 1000000, datetime.timezone.utc).replace(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

datetime.UTC was added in 3.11, so use datetime.timezone.utc to support 3.9/3.10

@zhengruifeng zhengruifeng requested a review from HyukjinKwon June 24, 2024 10:59
@zhengruifeng zhengruifeng deleted the fix_ntz_conversion branch June 24, 2024 12:16
@zhengruifeng
Copy link
Contributor Author

merged to master

attilapiros pushed a commit to attilapiros/spark that referenced this pull request Oct 4, 2024
…recated methods

### What changes were proposed in this pull request?
`TimestampNTZType.fromInternal` not use the deprecated methods

### Why are the changes needed?
```
In [2]: ts = 111111111111

In [3]: datetime.datetime.utcfromtimestamp(ts // 1000000).replace(
   ...:                 microsecond=ts % 1000000
   ...:             )
<ipython-input-3-166450e5ec26>:1: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
  datetime.datetime.utcfromtimestamp(ts // 1000000).replace(
Out[3]: datetime.datetime(1970, 1, 2, 6, 51, 51, 111111)
```

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
new tests

### Was this patch authored or co-authored using generative AI tooling?
No

Closes apache#47068 from zhengruifeng/fix_ntz_conversion.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants