You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/08/29 19:12:29 UTC

[GitHub] [iceberg] rdblue opened a new pull request, #5667: Python: Fix date/time transforms

rdblue opened a new pull request, #5667:
URL: https://github.com/apache/iceberg/pull/5667

   This fixes some of the date/time transform methods introduced in #5462.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on a diff in pull request #5667: Python: Fix date/time transforms

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #5667:
URL: https://github.com/apache/iceberg/pull/5667#discussion_r957708991


##########
python/pyiceberg/utils/datetime.py:
##########
@@ -133,28 +133,24 @@ def to_human_timestamp(timestamp_micros: int) -> str:
     return (EPOCH_TIMESTAMP + timedelta(microseconds=timestamp_micros)).isoformat()
 
 
-def micros_to_hours(timestamp: int) -> int:
-    """Converts a timestamp in microseconds to a date in hours"""
-    return int((datetime.utcfromtimestamp(timestamp // 1_000_000) - EPOCH_TIMESTAMP).total_seconds() / 3600)
+def micros_to_hours(micros: int) -> int:
+    """Converts a timestamp in microseconds to hours from 1970-01-01T00:00"""
+    return micros // 3_600_000_000
 
 
 def days_to_months(days: int) -> int:
-    """Creates a date from the number of days from 1970-01-01"""
     d = days_to_date(days)
     return (d.year - EPOCH_DATE.year) * 12 + (d.month - EPOCH_DATE.month)
 
 
-def micros_to_months(timestamp: int) -> int:
-    dt = micros_to_timestamp(timestamp)
-    return (dt.year - EPOCH_TIMESTAMP.year) * 12 + (dt.month - EPOCH_TIMESTAMP.month) - (1 if dt.day < EPOCH_TIMESTAMP.day else 0)
+def micros_to_months(micros: int) -> int:
+    dt = micros_to_timestamp(micros)
+    return (dt.year - EPOCH_TIMESTAMP.year) * 12 + (dt.month - EPOCH_TIMESTAMP.month)
 
 
 def days_to_years(days: int) -> int:
     return days_to_date(days).year - EPOCH_DATE.year
 
 
-def micros_to_years(timestamp: int) -> int:
-    dt = micros_to_timestamp(timestamp)
-    return (dt.year - EPOCH_TIMESTAMP.year) - (
-        1 if dt.month < EPOCH_TIMESTAMP.month or (dt.month == EPOCH_TIMESTAMP.month and dt.day < EPOCH_TIMESTAMP.day) else 0

Review Comment:
   Month and day are never 0.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on a diff in pull request #5667: Python: Fix date/time transforms

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #5667:
URL: https://github.com/apache/iceberg/pull/5667#discussion_r957709655


##########
python/pyiceberg/utils/datetime.py:
##########
@@ -35,7 +35,7 @@
 
 def micros_to_days(timestamp: int) -> int:
     """Converts a timestamp in microseconds to a date in days"""
-    return (datetime.fromtimestamp(timestamp / 1_000_000) - EPOCH_TIMESTAMP).days
+    return timedelta(microseconds=timestamp).days

Review Comment:
   Here, we can go directly to delta rather than going to date and subtracting.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] Fokko merged pull request #5667: Python: Fix date/time transforms

Posted by GitBox <gi...@apache.org>.
Fokko merged PR #5667:
URL: https://github.com/apache/iceberg/pull/5667


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on a diff in pull request #5667: Python: Fix date/time transforms

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #5667:
URL: https://github.com/apache/iceberg/pull/5667#discussion_r957709337


##########
python/pyiceberg/utils/datetime.py:
##########
@@ -133,28 +133,24 @@ def to_human_timestamp(timestamp_micros: int) -> str:
     return (EPOCH_TIMESTAMP + timedelta(microseconds=timestamp_micros)).isoformat()
 
 
-def micros_to_hours(timestamp: int) -> int:
-    """Converts a timestamp in microseconds to a date in hours"""
-    return int((datetime.utcfromtimestamp(timestamp // 1_000_000) - EPOCH_TIMESTAMP).total_seconds() / 3600)
+def micros_to_hours(micros: int) -> int:
+    """Converts a timestamp in microseconds to hours from 1970-01-01T00:00"""
+    return micros // 3_600_000_000

Review Comment:
   This converts to a timestamp only to get back to a delta, and then get the seconds. Instead, we can convert directly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org