Skip to content

Commit 85b6324

Browse files
add .size to ArrowFile (#1944)
1 parent dae0e80 commit 85b6324

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

fsspec/implementations/arrow.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ def get_file(self, rpath, lpath, **kwargs):
223223
"readable",
224224
"writable",
225225
"close",
226-
"size",
227226
"seekable",
228227
],
229228
)
@@ -241,6 +240,10 @@ def __init__(self, fs, stream, path, mode, block_size=None, **kwargs):
241240
def __enter__(self):
242241
return self
243242

243+
@property
244+
def size(self):
245+
return self.stream.size()
246+
244247
def __exit__(self, *args):
245248
return self.close()
246249

fsspec/implementations/tests/test_arrow.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,8 @@ def test_get_file_seekable_default(fs, remote_dir, tmp_path):
280280

281281
# Test default behavior (seekable=False)
282282
local_file = tmp_path / "test_default.txt"
283-
fs.get_file(remote_dir + "/test_file.txt", str(local_file))
284-
with open(local_file, "rb") as f:
285-
assert f.read() == data
283+
with pytest.raises(OSError, match="only valid on seekable files"):
284+
fs.get_file(remote_dir + "/test_file.txt", str(local_file))
286285

287286
# Test with explicit seekable=True
288287
local_file_seekable = tmp_path / "test_seekable.txt"
@@ -292,11 +291,10 @@ def test_get_file_seekable_default(fs, remote_dir, tmp_path):
292291

293292
# Test with explicit seekable=False
294293
local_file_not_seekable = tmp_path / "test_not_seekable.txt"
295-
fs.get_file(
296-
remote_dir + "/test_file.txt", str(local_file_not_seekable), seekable=False
297-
)
298-
with open(local_file_not_seekable, "rb") as f:
299-
assert f.read() == data
294+
with pytest.raises(OSError, match="only valid on seekable files"):
295+
fs.get_file(
296+
remote_dir + "/test_file.txt", str(local_file_not_seekable), seekable=False
297+
)
300298

301299

302300
def test_cat_file_seekable_override(fs, remote_dir):
@@ -333,7 +331,7 @@ def test_seekable_true_allows_size_method(fs, remote_dir):
333331
with fs.open(test_file, "rb", seekable=True) as f:
334332
assert f.seekable() is True
335333
# Verify size() method works and returns correct size
336-
file_size = f.size()
334+
file_size = f.size
337335
assert file_size == len(data)
338336
# Also verify we can read the data
339337
assert f.read() == data
@@ -353,6 +351,6 @@ def test_seekable_false_prevents_size_method(fs, remote_dir):
353351
assert f.seekable() is False
354352
# Verify size() raises OSError
355353
with pytest.raises(OSError, match="only valid on seekable files"):
356-
f.size()
354+
_ = f.size
357355
# Verify we can still read the data
358356
assert f.read() == data

0 commit comments

Comments
 (0)