Add custom Duration and Timestamp classes with nanosecond support#975
Add custom Duration and Timestamp classes with nanosecond support#975hectorcast-db wants to merge 8 commits intomainfrom
Conversation
| def __init__(self, seconds: int = 0, nanoseconds: int = 0) -> None: | ||
| """Initialize a Duration with seconds and nanoseconds. | ||
|
|
||
| Args: | ||
| seconds: Number of seconds | ||
| nanoseconds: Number of nanoseconds (0-999999999) | ||
|
|
||
| Raises: | ||
| TypeError: If seconds or nanoseconds are not integers | ||
| ValueError: If nanoseconds is not between 0 and 999999999 | ||
| """ | ||
| if not isinstance(seconds, int): | ||
| raise TypeError("seconds must be an integer") | ||
| if not isinstance(nanoseconds, int): | ||
| raise TypeError("nanoseconds must be an integer") |
There was a problem hiding this comment.
Why do we need this type check when we explicitly stated that in the function arguments?
There was a problem hiding this comment.
The type in the arguments are only "hints" for the linter, but python does not enforce them.
| self.nanoseconds = nanoseconds | ||
|
|
||
| @classmethod | ||
| def from_timedelta(cls, td: timedelta) -> "Duration": |
There was a problem hiding this comment.
This is returning "Duration" with quotes. Is this expected?
There was a problem hiding this comment.
Yes. In Python you cannot use a type before introduced. This is a workaround introduced at some point:
databricks/sdk/common.py
Outdated
| from datetime import datetime, timedelta, timezone | ||
| from decimal import Decimal | ||
|
|
||
| _LOG = logging.getLogger("databricks.sdk") |
| """Common types for the Databricks SDK. | ||
|
|
||
| This module provides common types used by different APIs. | ||
| """ |
There was a problem hiding this comment.
Could we actually move this in databricks/sdk/core/common? I'd like to reserve databricks/sdk/common for SDK-Mod.
There was a problem hiding this comment.
moved to databricks/sdk/common_types/common.py since moving it to core creates circular dependencies witth the core.py file.
e9c4694 to
389e0c6
Compare
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
renaudhartert-db
left a comment
There was a problem hiding this comment.
This is not relevant anymore right?
|
Not relevant. |
What changes are proposed in this pull request?
Add custom Duration and Timestamp classes with nanosecond support and helper methods
How is this tested?
Added tests
NO_CHANGELOG=true