|
59 | 59 | BaseBuffer,
|
60 | 60 | ReadCsvBuffer,
|
61 | 61 | )
|
| 62 | +from pandas.compat import is_platform_windows |
62 | 63 | from pandas.compat._optional import import_optional_dependency
|
63 | 64 | from pandas.util._decorators import doc
|
64 | 65 | from pandas.util._exceptions import find_stack_level
|
@@ -1288,6 +1289,17 @@ def dedup_names(
|
1288 | 1289 | return names
|
1289 | 1290 |
|
1290 | 1291 |
|
| 1292 | +def _infer_protocol(path: str) -> str: |
| 1293 | + # Treat Windows drive letters like C:\ as local file paths |
| 1294 | + if is_platform_windows() and re.match(r"^[a-zA-Z]:[\\/]", path): |
| 1295 | + return "file" |
| 1296 | + |
| 1297 | + parsed = parse_url(path) |
| 1298 | + if parsed.scheme in _VALID_URLS: |
| 1299 | + return parsed.scheme |
| 1300 | + return "file" |
| 1301 | + |
| 1302 | + |
1291 | 1303 | def _match_file(
|
1292 | 1304 | path: Path | PurePosixPath, extensions: set[str] | None, glob: str | None
|
1293 | 1305 | ) -> bool:
|
@@ -1351,15 +1363,11 @@ def iterdir(
|
1351 | 1363 | else:
|
1352 | 1364 | extensions = {ext.lower() for ext in extensions}
|
1353 | 1365 |
|
1354 |
| - if isinstance(path, os.PathLike): |
1355 |
| - path = os.fspath(path) |
1356 |
| - |
1357 |
| - parsed = parse_url(path) |
1358 |
| - scheme = parsed.scheme or "file" |
1359 |
| - base_path = parsed.path if scheme == "file" else path |
| 1366 | + path_str = os.fspath(path) |
| 1367 | + scheme = _infer_protocol(path_str) |
1360 | 1368 |
|
1361 | 1369 | if scheme == "file":
|
1362 |
| - resolved_path = Path(base_path) |
| 1370 | + resolved_path = Path(path_str) |
1363 | 1371 | if resolved_path.is_file():
|
1364 | 1372 | if _match_file(
|
1365 | 1373 | resolved_path,
|
@@ -1397,7 +1405,7 @@ def iterdir(
|
1397 | 1405 | yield path_obj
|
1398 | 1406 | return
|
1399 | 1407 | if not fs.isdir(path):
|
1400 |
| - raise NotADirectoryError(f"Remote path {path!r} is not a directory.") |
| 1408 | + raise NotADirectoryError(f"Path {path!r} is neither a file nor a directory.") |
1401 | 1409 |
|
1402 | 1410 | files = fs.ls(path, detail=True)
|
1403 | 1411 | for f in files:
|
|
0 commit comments