Skip to content

Commit 42285e3

Browse files
committed
feat: use tell() instead of __len__
1 parent b85fe99 commit 42285e3

File tree

4 files changed

+6
-15
lines changed

4 files changed

+6
-15
lines changed

pyiceberg/avro/file.py

+2-2
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def __exit__(
125125
"""Perform cleanup when exiting the scope of a 'with' statement."""
126126

127127
@abstractmethod
128-
def __len__(self) -> int:
129-
"""Returns the total number number of bytes written to the stream."""
128+
def tell(self) -> int:
129+
"""Return the total number number of bytes written to the stream."""
130130

131131

132132
class InputFile(ABC):

pyiceberg/manifest.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -778,11 +778,10 @@ def add_entry(self, entry: ManifestEntry) -> ManifestWriter:
778778
return self
779779

780780
def __len__(self) -> int:
781-
"""Returns the total number number of bytes written."""
781+
"""Return the total number number of bytes written."""
782782
return len(self._writer)
783783

784784

785-
786785
class RollingManifestWriter:
787786
closed: bool
788787
_supplier: Generator[ManifestWriter, None, None]
@@ -833,8 +832,7 @@ def _should_roll_to_new_file(self) -> bool:
833832
if not self._current_writer:
834833
return False
835834
return (
836-
self._current_file_rows >= self._target_number_of_rows
837-
or len(self._current_writer) >= self._target_file_size_in_bytes
835+
self._current_file_rows >= self._target_number_of_rows or len(self._current_writer) >= self._target_file_size_in_bytes
838836
)
839837

840838
def _close_current_writer(self) -> None:

tests/utils/test_manifest.py

-7
Original file line numberDiff line numberDiff line change
@@ -516,13 +516,6 @@ def test_rolling_manifest_writer(
516516
spec_id=demo_manifest_file.partition_spec_id,
517517
)
518518

519-
# The tests are using `PyArrowFileIO` where `OutputStream` is implemented as `pyarrow.lib.BufferedOutputStream`
520-
# this is just to show the tests passing if `pyarrow.lib.BufferedOutputStream` would implement the
521-
# new `OutputStream` protocol that includes a `__len__` method
522-
from pyiceberg.avro.file import AvroOutputFile
523-
AvroOutputFile.__len__ = lambda self: self.output_stream.tell()
524-
525-
526519
with TemporaryDirectory() as tmpdir:
527520

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

0 commit comments

Comments
 (0)