Skip to content

Commit cea9d7c

Browse files
Return None for size if arrow file is not seekable (#1981)
Fixes #1978 Co-authored-by: Martin Durant <martin.durant@alumni.utoronto.ca>
1 parent 6e11963 commit cea9d7c

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

fsspec/implementations/arrow.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ def __enter__(self):
242242

243243
@property
244244
def size(self):
245-
return self.stream.size()
245+
if self.stream.seekable():
246+
return self.stream.size()
247+
return None
246248

247249
def __exit__(self, *args):
248250
return self.close()

fsspec/implementations/tests/test_arrow.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,9 @@ 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-
with pytest.raises(OSError, match="only valid on seekable files"):
284-
fs.get_file(remote_dir + "/test_file.txt", str(local_file))
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
285286

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

292293
# Test with explicit seekable=False
293294
local_file_not_seekable = tmp_path / "test_not_seekable.txt"
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-
)
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
298300

299301

300302
def test_cat_file_seekable_override(fs, remote_dir):
@@ -338,7 +340,7 @@ def test_seekable_true_allows_size_method(fs, remote_dir):
338340

339341

340342
def test_seekable_false_prevents_size_method(fs, remote_dir):
341-
"""Test that size() method raises OSError when seekable=False."""
343+
"""Test that size() method returns None when seekable=False."""
342344
data = b"test data for size method" * 10
343345

344346
# Create a test file
@@ -349,8 +351,7 @@ def test_seekable_false_prevents_size_method(fs, remote_dir):
349351
# Open with seekable=False - size() should raise OSError
350352
with fs.open(test_file, "rb", seekable=False) as f:
351353
assert f.seekable() is False
352-
# Verify size() raises OSError
353-
with pytest.raises(OSError, match="only valid on seekable files"):
354-
_ = f.size
354+
# Verify size() returns None
355+
assert f.size is None
355356
# Verify we can still read the data
356357
assert f.read() == data

0 commit comments

Comments
 (0)