From 087b5bcd22cff1b43d8506d9710e8f2aeab0563d Mon Sep 17 00:00:00 2001 From: moto <855818+mthrok@users.noreply.github.com> Date: Thu, 26 Dec 2024 16:32:41 -0500 Subject: [PATCH] Make all the DataLoader attributes private --- src/spdl/dataloader/_dataloader.py | 44 ++++++++++++++---------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/spdl/dataloader/_dataloader.py b/src/spdl/dataloader/_dataloader.py index 2449ddaf..9be9c2e8 100644 --- a/src/spdl/dataloader/_dataloader.py +++ b/src/spdl/dataloader/_dataloader.py @@ -96,8 +96,6 @@ class DataLoader(Generic[Source, Output]): passed to the aggregator in order of completion. If 'input', then they are passed to the aggregator in the order of the source input. - :ivar src: The source object provided in the constructor. - Exapmles: >>> import spdl.io >>> from spdl.io import ImageFrames @@ -194,37 +192,37 @@ def __init__( timeout: float | None = None, output_order: str = "completion", ) -> None: - self.src = src - self.preprocessor = preprocessor - self.aggregator = aggregator + self._src = src + self._preprocessor = preprocessor + self._aggregator = aggregator - self.batch_size = batch_size - self.drop_last = drop_last - self.buffer_size = buffer_size - self.num_threads = num_threads - self.timeout = timeout - self.output_order = output_order + self._batch_size = batch_size + self._drop_last = drop_last + self._buffer_size = buffer_size + self._num_threads = num_threads + self._timeout = timeout + self._output_order = output_order def _get_pipeline(self) -> Pipeline: builder = PipelineBuilder() - builder.add_source(self.src) + builder.add_source(self._src) - if self.preprocessor: + if self._preprocessor: builder.pipe( - self.preprocessor, - concurrency=self.num_threads, - output_order=self.output_order, + self._preprocessor, + concurrency=self._num_threads, + output_order=self._output_order, ) - if self.batch_size: - builder.aggregate(self.batch_size, drop_last=self.drop_last) + if self._batch_size: + builder.aggregate(self._batch_size, drop_last=self._drop_last) - if self.aggregator: - builder.pipe(self.aggregator) + if self._aggregator: + builder.pipe(self._aggregator) - builder.add_sink(self.buffer_size) + builder.add_sink(self._buffer_size) - return builder.build(num_threads=self.num_threads) + return builder.build(num_threads=self._num_threads) def __iter__(self) -> Iterable[Output]: """Run the data loading pipeline in background. @@ -235,5 +233,5 @@ def __iter__(self) -> Iterable[Output]: pipeline = self._get_pipeline() with pipeline.auto_stop(): - for item in pipeline.get_iterator(timeout=self.timeout): + for item in pipeline.get_iterator(timeout=self._timeout): yield item