Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyiceberg/avro/decoder_fast.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ cdef class CythonBinaryDecoder:
"""
return float(STRUCT_FLOAT.unpack(self.read(4))[0])

cpdef float read_double(self):
cpdef double read_double(self):
"""Reads a value from the stream as a double.

A double is written as 8 bytes.
Expand Down
17 changes: 17 additions & 0 deletions tests/avro/test_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@ def test_read_double(decoder_class: Callable[[bytes], BinaryDecoder]) -> None:
assert decoder.read_double() == 19.25


@pytest.mark.parametrize("decoder_class", AVAILABLE_DECODERS)
@pytest.mark.parametrize(
"value",
[
3.141592653589793,
429496729622.314,
0.1,
1.0000000000000002, # smallest double above 1.0
1e308, # overflows to inf in single precision
5e-324, # underflows to 0.0 in single precision
],
)
def test_read_double_keeps_full_precision(decoder_class: Callable[[bytes], BinaryDecoder], value: float) -> None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a valid regression test. It passes even if we revert decoder_fast.pyx's change.

decoder = decoder_class(struct.pack("<d", value))
assert decoder.read_double() == value


@pytest.mark.parametrize("decoder_class", AVAILABLE_DECODERS)
def test_skip_double(decoder_class: Callable[[bytes], BinaryDecoder]) -> None:
decoder = decoder_class(b"\x00\x00\x00\x00\x00\x40\x33\x40")
Expand Down
Loading