Skip to content

Commit 87c44a4

Browse files
committed
feat: use tell() instead of __len__
1 parent a9123b8 commit 87c44a4

File tree

4 files changed

+6
-14
lines changed

4 files changed

+6
-14
lines changed

pyiceberg/avro/file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def write_block(self, objects: List[D]) -> None:
290290
self.encoder.write(self.sync_bytes)
291291

292292
def __len__(self) -> int:
293-
"""Returns the total number number of bytes written."""
293+
"""Return the total number number of bytes written."""
294294
if self.closed:
295295
return len(self.output_file)
296-
return len(self.output_stream)
296+
return self.output_stream.tell()

pyiceberg/io/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ def __exit__(
133133
"""Perform cleanup when exiting the scope of a 'with' statement."""
134134

135135
@abstractmethod
136-
def __len__(self) -> int:
137-
"""Returns the total number number of bytes written to the stream."""
136+
def tell(self) -> int:
137+
"""Return the total number number of bytes written to the stream."""
138138

139139

140140
class InputFile(ABC):

pyiceberg/manifest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ def existing(self, entry: ManifestEntry) -> ManifestWriter:
887887

888888

889889
def __len__(self) -> int:
890-
"""Returns the total number number of bytes written."""
890+
"""Return the total number number of bytes written."""
891891
return len(self._writer)
892892

893893

@@ -938,8 +938,7 @@ def _should_roll_to_new_file(self) -> bool:
938938
if not self._current_writer:
939939
return False
940940
return (
941-
self._current_file_rows >= self._target_number_of_rows
942-
or len(self._current_writer) >= self._target_file_size_in_bytes
941+
self._current_file_rows >= self._target_number_of_rows or len(self._current_writer) >= self._target_file_size_in_bytes
943942
)
944943

945944
def _close_current_writer(self):

tests/utils/test_manifest.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -533,13 +533,6 @@ def test_rolling_manifest_writer(
533533
spec_id=demo_manifest_file.partition_spec_id,
534534
)
535535

536-
# The tests are using `PyArrowFileIO` where `OutputStream` is implemented as `pyarrow.lib.BufferedOutputStream`
537-
# this is just to show the tests passing if `pyarrow.lib.BufferedOutputStream` would implement the
538-
# new `OutputStream` protocol that includes a `__len__` method
539-
from pyiceberg.avro.file import AvroOutputFile
540-
AvroOutputFile.__len__ = lambda self: self.output_stream.tell()
541-
542-
543536
with TemporaryDirectory() as tmpdir:
544537

545538
def supplier() -> Generator[ManifestWriter, None, None]:

0 commit comments

Comments
 (0)