This is an automated email from the ASF dual-hosted git repository.

kevinjqliu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git


The following commit(s) were added to refs/heads/main by this push:
     new 93554a47 fix: nanos_to_hours returning incorrect hour values (#2920)
93554a47 is described below

commit 93554a475e681192c783bc2251793a8fd514084e
Author: geruh <[email protected]>
AuthorDate: Mon Jan 19 15:04:24 2026 -0800

    fix: nanos_to_hours returning incorrect hour values (#2920)
    
    # Rationale for this change
    This PR removes an extra 0 from the nanos_to_hours conversion method
    which resulted in incorrect partitioning. Found this while testing out
    the V3 `TimestampNanoType` and partitioning.
    
    ## Are these changes tested?
    Yes, I added some tests from the java side to ensure we align.
    
    -
    
https://github.com/apache/iceberg/blob/9b573c7b46950a41d614c4240752f255282d8c1f/api/src/test/java/org/apache/iceberg/util/TestDateTimeUtil.java#L70
    
    ## Are there any user-facing changes?
    No
---
 pyiceberg/utils/datetime.py  |  2 +-
 tests/utils/test_datetime.py | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/pyiceberg/utils/datetime.py b/pyiceberg/utils/datetime.py
index 46bbb32d..b5cde34f 100644
--- a/pyiceberg/utils/datetime.py
+++ b/pyiceberg/utils/datetime.py
@@ -273,7 +273,7 @@ def nanos_to_time(nanos: int) -> time:
 
 def nanos_to_hours(nanos: int) -> int:
     """Convert a timestamp in nanoseconds to hours from 1970-01-01T00:00."""
-    return nanos // 3_600_000_000_0000
+    return nanos // 3_600_000_000_000
 
 
 def nanos_to_micros(nanos: int) -> int:
diff --git a/tests/utils/test_datetime.py b/tests/utils/test_datetime.py
index 6f6f4a91..673908e1 100644
--- a/tests/utils/test_datetime.py
+++ b/tests/utils/test_datetime.py
@@ -23,6 +23,7 @@ from pyiceberg.utils.datetime import (
     datetime_to_millis,
     datetime_to_nanos,
     millis_to_datetime,
+    nanos_to_hours,
     nanos_to_micros,
     time_str_to_nanos,
     time_to_nanos,
@@ -132,3 +133,14 @@ def test_timestamptz_to_nanos(timestamp: str, nanos: int) 
-> None:
 @pytest.mark.parametrize("nanos, micros", [(1510871468000001001, 
1510871468000001), (-1510871468000001001, -1510871468000002)])
 def test_nanos_to_micros(nanos: int, micros: int) -> None:
     assert micros == nanos_to_micros(nanos)
+
+
[email protected](
+    "nanos, hours",
+    [
+        (1510871468000001001, 419686),
+        (-1510871468000001001, -419687),
+    ],
+)
+def test_nanos_to_hours(nanos: int, hours: int) -> None:
+    assert hours == nanos_to_hours(nanos)

Reply via email to