Skip to content

Commit b8eed8c

Browse files
authored
GH-47559: [Python] Fix missing argument in pyarrow fs (#47497)
### Rationale for this change Fix a syntax error in Python. The argument is required. ### What changes are included in this PR? * Fix a syntax error in pyarrow fs ### Are these changes tested? Yes ### Are there any user-facing changes? No * GitHub Issue: #47559 Authored-by: TennyZhuang <zty0826@gmail.com> Signed-off-by: Raúl Cumplido <raulcumplido@gmail.com>
1 parent ea3b8c6 commit b8eed8c

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

python/pyarrow/fs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def delete_dir_contents(self, path, missing_dir_ok):
382382
self._delete_dir_contents(path, missing_dir_ok)
383383

384384
def delete_root_dir_contents(self):
385-
self._delete_dir_contents("/")
385+
self._delete_dir_contents("/", False)
386386

387387
def delete_file(self, path):
388388
# fs.rm correctly raises IsADirectoryError when `path` is a directory

python/pyarrow/tests/test_fs.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@ def _check_root_dir_contents(config):
906906
fs.delete_dir_contents("", accept_root_dir=True)
907907
fs.delete_dir_contents("/", accept_root_dir=True)
908908
fs.delete_dir_contents("//", accept_root_dir=True)
909+
909910
with pytest.raises(pa.ArrowIOError):
910911
fs.delete_dir(d)
911912

@@ -2206,6 +2207,41 @@ def test_fsspec_filesystem_from_uri():
22062207
assert fs == expected_fs
22072208

22082209

2210+
def test_fsspec_delete_root_dir_contents():
2211+
try:
2212+
from fsspec.implementations.memory import MemoryFileSystem
2213+
except ImportError:
2214+
pytest.skip("fsspec not installed")
2215+
2216+
fs = FSSpecHandler(MemoryFileSystem())
2217+
2218+
# Create some files and directories
2219+
fs.create_dir("test_dir", recursive=True)
2220+
fs.create_dir("test_dir/subdir", recursive=True)
2221+
2222+
with fs.open_output_stream("test_file.txt", metadata={}) as stream:
2223+
stream.write(b"test content")
2224+
2225+
with fs.open_output_stream("test_dir/nested_file.txt", metadata={}) as stream:
2226+
stream.write(b"nested content")
2227+
2228+
# Verify files exist before deletion
2229+
def get_type(path):
2230+
return fs.get_file_info([path])[0].type
2231+
2232+
assert get_type("test_file.txt") == FileType.File
2233+
assert get_type("test_dir") == FileType.Directory
2234+
assert get_type("test_dir/nested_file.txt") == FileType.File
2235+
2236+
# Delete root directory contents
2237+
fs.delete_root_dir_contents()
2238+
2239+
# Assert all files and directories are deleted
2240+
assert get_type("test_file.txt") == FileType.NotFound
2241+
assert get_type("test_dir") == FileType.NotFound
2242+
assert get_type("test_dir/nested_file.txt") == FileType.NotFound
2243+
2244+
22092245
def test_huggingface_filesystem_from_uri():
22102246
pytest.importorskip("fsspec")
22112247
try:

0 commit comments

Comments
 (0)