Skip to content

Commit 56bb9a6

Browse files
committed
fix error msg
1 parent 3e4b032 commit 56bb9a6

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

pandas/io/common.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,26 +1384,33 @@ def iterdir(
13841384

13851385
if scheme == "file":
13861386
resolved_path = _resolve_local_path(path_str)
1387+
if not resolved_path.exists():
1388+
raise FileNotFoundError(f"No such file or directory: '{resolved_path}'")
1389+
1390+
result = []
13871391
if resolved_path.is_file():
13881392
if _match_file(
13891393
resolved_path,
13901394
extensions,
13911395
glob,
13921396
):
1393-
return [resolved_path]
1394-
else:
1395-
return []
1397+
result.append(resolved_path)
1398+
return result
1399+
1400+
if resolved_path.is_dir():
1401+
for entry in resolved_path.iterdir():
1402+
if entry.is_file():
1403+
if _match_file(
1404+
entry,
1405+
extensions,
1406+
glob,
1407+
):
1408+
result.append(entry)
1409+
return result
13961410

1397-
result = []
1398-
for entry in resolved_path.iterdir():
1399-
if entry.is_file():
1400-
if _match_file(
1401-
entry,
1402-
extensions,
1403-
glob,
1404-
):
1405-
result.append(entry)
1406-
return result
1411+
raise ValueError(
1412+
f"The path '{resolved_path}' is neither a file nor a directory."
1413+
)
14071414

14081415
# Remote paths
14091416
fsspec = import_optional_dependency("fsspec", extra=scheme)

pandas/tests/io/parser/common/test_file_buffer_url.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,9 @@ def test_nonexistent_path(all_parsers):
8989
parser = all_parsers
9090
path = f"{uuid.uuid4()}.csv"
9191

92-
msg = r"\[Errno 2\]"
93-
with pytest.raises(FileNotFoundError, match=msg) as e:
92+
msg = rf"No such file or directory: '{path}'"
93+
with pytest.raises(FileNotFoundError, match=msg):
9494
parser.read_csv(path)
95-
assert path == e.value.filename
9695

9796

9897
@pytest.mark.skipif(WASM, reason="limited file system access on WASM")

pandas/tests/io/test_common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,9 @@ def test_iterdir_local(local_csv_directory):
703703
assert file.suffix == ".csv"
704704

705705

706+
def test_iterdir_local_passthrough(local_csv_directory): ...
707+
708+
706709
def test_remote_csv_directory(remote_csv_directory):
707710
import fsspec
708711
from fsspec.implementations.memory import MemoryFileSystem

0 commit comments

Comments
 (0)