Skip to content

Commit 0b43c35

Browse files
fix review
Signed-off-by: OneSizeFitsQuorum <[email protected]>
1 parent 41d05fd commit 0b43c35

File tree

3 files changed

+5
-52
lines changed

3 files changed

+5
-52
lines changed

fsspec/callbacks.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -91,29 +91,8 @@ def set_size(self, size):
9191
9292
Parameters
9393
----------
94-
size: int or callable
95-
The total size of the transfer. Can be either:
96-
- An integer representing the total size directly
97-
- A callable (function/method) that returns an integer when invoked
98-
99-
The callable option is useful when the size is only available as a
100-
method on an object (e.g., filesystem objects that have a ``size()``
101-
method instead of a ``size`` attribute).
102-
103-
Examples
104-
--------
105-
>>> callback = Callback()
106-
>>> callback.set_size(1000) # Direct integer
107-
>>> callback.set_size(lambda: 1000) # Callable returning integer
108-
109-
Notes
110-
-----
111-
If a callable is provided, it will be invoked immediately to obtain
112-
the size value. The callable should take no arguments and return an
113-
integer.
94+
size: int
11495
"""
115-
if callable(size):
116-
size = size()
11796
self.size = size
11897
self.call()
11998

fsspec/implementations/arrow.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ def __init__(self, fs, stream, path, mode, block_size=None, **kwargs):
241241
def __enter__(self):
242242
return self
243243

244+
@property
245+
def size(self):
246+
return self.stream.size()
247+
244248
def __exit__(self, *args):
245249
return self.close()
246250

fsspec/tests/test_callbacks.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -72,36 +72,6 @@ def relative_update(self, inc=1):
7272

7373
assert events == [1] * 10
7474

75-
76-
def test_set_size_with_callable():
77-
"""Test that set_size accepts both int and callable parameters."""
78-
callback = Callback()
79-
80-
# Test with integer
81-
callback.set_size(100)
82-
assert callback.size == 100
83-
84-
# Test with callable (lambda)
85-
callback.set_size(lambda: 200)
86-
assert callback.size == 200
87-
88-
# Test with callable (function)
89-
def get_size():
90-
return 300
91-
92-
callback.set_size(get_size)
93-
assert callback.size == 300
94-
95-
# Test with callable that simulates a method attribute
96-
class MockFileSystem:
97-
def size(self):
98-
return 400
99-
100-
fs = MockFileSystem()
101-
callback.set_size(fs.size)
102-
assert callback.size == 400
103-
104-
10575
@pytest.mark.parametrize("tqdm_kwargs", [{}, {"desc": "A custom desc"}])
10676
def test_tqdm_callback(tqdm_kwargs, mocker):
10777
pytest.importorskip("tqdm")

0 commit comments

Comments
 (0)