Skip to content

Commit 5d4c93f

Browse files
committed
fmt
1 parent f2e921b commit 5d4c93f

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

databricks/sdk/common.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def from_timedelta(cls, td: timedelta) -> "Duration":
6464
# Get the fractional part and convert to nanoseconds
6565
# This preserves more precision than using microsecond * 1000
6666
fractional = total_seconds - seconds
67-
nanoseconds = int(fractional * Decimal('1000000000'))
67+
nanoseconds = int(fractional * Decimal("1000000000"))
6868
return cls(seconds=seconds, nanoseconds=nanoseconds)
6969

7070
def to_timedelta(self) -> timedelta:
@@ -150,9 +150,9 @@ def to_string(self) -> str:
150150
return f"{self.seconds}s"
151151

152152
# Use Decimal for precise decimal arithmetic
153-
total = Decimal(self.seconds) + (Decimal(self.nanoseconds) / Decimal('1000000000'))
153+
total = Decimal(self.seconds) + (Decimal(self.nanoseconds) / Decimal("1000000000"))
154154
# Format with up to 9 decimal places, removing trailing zeros
155-
return f"{total:.9f}".rstrip('0').rstrip('.') + 's'
155+
return f"{total:.9f}".rstrip("0").rstrip(".") + "s"
156156

157157

158158
class Timestamp:
@@ -213,16 +213,16 @@ def from_datetime(cls, dt: datetime) -> "Timestamp":
213213
dt = dt.replace(tzinfo=timezone.utc)
214214
# Convert to UTC
215215
utc_dt = dt.astimezone(timezone.utc)
216-
216+
217217
# Get seconds since epoch using Decimal for precise calculation
218218
# datetime.timestamp() returns float, so we need to handle it carefully
219219
ts = Decimal(str(utc_dt.timestamp()))
220220
seconds = int(ts)
221221
# Get the fractional part and convert to nanoseconds
222222
# This preserves more precision than using microsecond * 1000
223223
fractional = ts - seconds
224-
nanos = int(fractional * Decimal('1000000000'))
225-
224+
nanos = int(fractional * Decimal("1000000000"))
225+
226226
return cls(seconds=seconds, nanos=nanos)
227227

228228
def to_datetime(self) -> datetime:
@@ -267,7 +267,7 @@ def parse(cls, timestamp_str: str) -> "Timestamp":
267267

268268
# Build the datetime string with a standardized offset format
269269
dt_str = f"{year}-{month}-{day}T{hour}:{minute}:{second}"
270-
270+
271271
# Handle fractional seconds, truncating to microseconds for fromisoformat
272272
nanos = 0
273273
if frac:
@@ -343,6 +343,6 @@ def replace(self, **kwargs) -> "Timestamp":
343343
Returns:
344344
A new Timestamp instance with the specified fields replaced
345345
"""
346-
seconds = kwargs.get('seconds', self.seconds)
347-
nanos = kwargs.get('nanos', self.nanos)
346+
seconds = kwargs.get("seconds", self.seconds)
347+
nanos = kwargs.get("nanos", self.nanos)
348348
return Timestamp(seconds=seconds, nanos=nanos)

tests/test_common.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,15 @@ def test_timestamp_from_datetime(dt, expected_seconds, expected_nanos):
141141
],
142142
)
143143
def test_timestamp_to_datetime(
144-
seconds, nanos, expected_year, expected_month, expected_day, expected_hour, expected_minute, expected_second, expected_microsecond
144+
seconds,
145+
nanos,
146+
expected_year,
147+
expected_month,
148+
expected_day,
149+
expected_hour,
150+
expected_minute,
151+
expected_second,
152+
expected_microsecond,
145153
):
146154
"""Test conversion from Timestamp to datetime."""
147155
ts = Timestamp(seconds=seconds, nanos=nanos)
@@ -225,7 +233,7 @@ def test_timestamp_equality(ts1, ts2, expected_equal):
225233
)
226234
def test_duration_float_precision(seconds, nanoseconds, expected_microseconds):
227235
"""Test Duration float precision handling with various nanosecond values.
228-
236+
229237
Note: timedelta only supports microsecond precision (6 decimal places),
230238
so nanosecond values are rounded to the nearest microsecond.
231239
"""
@@ -254,7 +262,7 @@ def test_duration_float_precision(seconds, nanoseconds, expected_microseconds):
254262
)
255263
def test_duration_parse_precision(duration_str, expected_microseconds):
256264
"""Test Duration parsing precision with various decimal values.
257-
265+
258266
Note: timedelta only supports microsecond precision (6 decimal places),
259267
so nanosecond values are rounded to the nearest microsecond.
260268
"""

0 commit comments

Comments
 (0)