File tree Expand file tree Collapse file tree 3 files changed +16
-22
lines changed Expand file tree Collapse file tree 3 files changed +16
-22
lines changed Original file line number Diff line number Diff line change @@ -1378,11 +1378,6 @@ def iterdir(
1378
1378
yield resolved_path
1379
1379
return
1380
1380
1381
- if not resolved_path .is_dir ():
1382
- raise NotADirectoryError (
1383
- f"Path { path !r} is neither a file nor a directory."
1384
- )
1385
-
1386
1381
for entry in resolved_path .iterdir ():
1387
1382
if entry .is_file ():
1388
1383
if _match_file (
@@ -1393,7 +1388,7 @@ def iterdir(
1393
1388
yield entry
1394
1389
return
1395
1390
1396
- # Remote paths (e.g., s3)
1391
+ # Remote paths
1397
1392
fsspec = import_optional_dependency ("fsspec" , extra = scheme )
1398
1393
fs = fsspec .filesystem (scheme )
1399
1394
path_without_scheme = fsspec .core .strip_protocol (path_str )
@@ -1405,13 +1400,10 @@ def iterdir(
1405
1400
):
1406
1401
yield PurePosixPath (path_without_scheme )
1407
1402
return
1408
- if not fs .isdir (path_without_scheme ):
1409
- raise NotADirectoryError (f"Path { path !r} is neither a file nor a directory." )
1410
1403
1411
- files = fs .ls (path_without_scheme , detail = True )
1412
- for f in files :
1413
- if f ["type" ] == "file" :
1414
- path_obj = PurePosixPath (f ["name" ])
1404
+ for file in fs .ls (path_without_scheme , detail = True ):
1405
+ if fs .isfile (file ):
1406
+ path_obj = PurePosixPath (file ["name" ])
1415
1407
if _match_file (
1416
1408
path_obj ,
1417
1409
extensions ,
Original file line number Diff line number Diff line change @@ -226,18 +226,18 @@ def compression_ext(request):
226
226
227
227
228
228
@pytest .fixture
229
- def directory_with_dummy_csv (tmp_path ):
229
+ def local_csv_directory (tmp_path ):
230
230
"""
231
231
Fixture to create a directory with dummy CSV files for testing.
232
232
"""
233
233
for i in range (3 ):
234
- file_path = tmp_path / f"file_ { i } .csv"
234
+ file_path = tmp_path / f"{ i } .csv"
235
235
file_path .touch ()
236
236
return tmp_path
237
237
238
238
239
239
@pytest .fixture
240
- def mock_remote_csv_directory (monkeypatch ):
240
+ def remote_csv_directory (monkeypatch ):
241
241
_ = pytest .importorskip ("fsspec" , reason = "fsspec is required for remote tests" )
242
242
243
243
from fsspec .implementations .memory import MemoryFileSystem
Original file line number Diff line number Diff line change @@ -697,14 +697,13 @@ def test_pyarrow_read_csv_datetime_dtype():
697
697
tm .assert_frame_equal (expect , result )
698
698
699
699
700
- def test_iterdir_local (directory_with_dummy_csv ):
701
- for file in icom .iterdir (directory_with_dummy_csv ):
700
+ def test_iterdir_local (local_csv_directory ):
701
+ for file in icom .iterdir (local_csv_directory ):
702
702
assert file .is_file ()
703
- assert file .name .startswith ("file_" )
704
703
assert file .suffix == ".csv"
705
704
706
705
707
- def test_mock_remote_csv_directory_contents ( mock_remote_csv_directory ):
706
+ def test_remote_csv_directory ( remote_csv_directory ):
708
707
import fsspec
709
708
from fsspec .implementations .memory import MemoryFileSystem
710
709
@@ -726,10 +725,13 @@ def test_mock_remote_csv_directory_contents(mock_remote_csv_directory):
726
725
assert nested_files [0 ]["name" ] == "/remote-bucket/nested/ignored.csv"
727
726
728
727
729
- def test_iterdir_remote (mock_remote_csv_directory ):
728
+ def test_iterdir_remote (remote_csv_directory ):
730
729
import fsspec
731
730
732
731
fs = fsspec .filesystem ("s3" )
733
- for file in icom .iterdir (mock_remote_csv_directory ):
734
- assert fs .isfile (file )
732
+ for file in icom .iterdir (remote_csv_directory ):
733
+ assert fs .exists (file )
735
734
assert file .suffix == ".csv"
735
+
736
+ # for fsspec<2024.5.0, fs.isfle(PurePosixPath) returns False
737
+ assert fs .isfile (str (file ))
You can’t perform that action at this time.
0 commit comments