Skip to content

Commit

Permalink
Fix embarassing bug in truncate
Browse files Browse the repository at this point in the history
  • Loading branch information
aandres committed Jul 13, 2023
1 parent 3a1d70a commit dce4e9a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 1 addition & 2 deletions tests/random_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ def truncate_nanos(message: Message, timestamp_unit: str, time_unit: str) -> Mes
else:
for item in field_value:
truncate_nanos(item, timestamp_unit, time_unit)
else:
message.HasField(field.name)
elif message.HasField(field.name):
truncate_nanos(
getattr(message, field.name), timestamp_unit, time_unit
)
Expand Down
20 changes: 20 additions & 0 deletions tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,26 @@ def test_truncate_nested():
)


def test_truncate_nested_nested():
assert truncate_nanos(
NestedExampleMessage(
example_message=ExampleMessage(
timestamp_value=Timestamp(seconds=10, nanos=123_456_789),
timestamp_string_map={"foo": Timestamp(seconds=10, nanos=123_456_789)},
time_of_day_value=TimeOfDay(hours=1, nanos=123_456_789),
),
),
"us",
"ms",
) == NestedExampleMessage(
example_message=ExampleMessage(
timestamp_value=Timestamp(seconds=10, nanos=123_456_000),
timestamp_string_map={"foo": Timestamp(seconds=10, nanos=123_456_000)},
time_of_day_value=TimeOfDay(hours=1, nanos=123_000_000),
)
)


@pytest.mark.parametrize(
"enum_type", [pa.binary(), pa.dictionary(pa.int32(), pa.binary())]
)
Expand Down

0 comments on commit dce4e9a

Please sign in to comment.