Skip to content

Commit d77d290

Browse files
committed
fix format
1 parent a2b65e1 commit d77d290

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

pandas/io/common.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
overload,
4747
)
4848
from urllib.parse import (
49+
unquote,
4950
urljoin,
5051
urlparse as parse_url,
5152
uses_netloc,
@@ -1323,6 +1324,13 @@ def _match_file(
13231324
)
13241325

13251326

1327+
def _resolve_local_path(path_str: str) -> Path:
1328+
parsed = parse_url(path_str)
1329+
if is_platform_windows() and parsed.netloc:
1330+
return Path(f"{parsed.netloc}{parsed.path}")
1331+
return Path(unquote(parsed.path))
1332+
1333+
13261334
def iterdir(
13271335
path: FilePath | BaseBuffer,
13281336
extensions: str | Iterable[str] | None = None,
@@ -1361,6 +1369,11 @@ def iterdir(
13611369
if hasattr(path, "read") or hasattr(path, "write"):
13621370
return path
13631371

1372+
if not isinstance(path, (str, os.PathLike)):
1373+
raise TypeError(
1374+
f"Expected file path name or file-like object, got {type(path)} type"
1375+
)
1376+
13641377
if extensions is not None:
13651378
if isinstance(extensions, str):
13661379
extensions = {extensions.lower()}
@@ -1371,7 +1384,7 @@ def iterdir(
13711384
scheme = _infer_protocol(path_str)
13721385

13731386
if scheme == "file":
1374-
resolved_path = Path(path_str)
1387+
resolved_path = _resolve_local_path(path_str)
13751388
if resolved_path.is_file():
13761389
if _match_file(
13771390
resolved_path,

pandas/io/parsers/readers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -729,21 +729,22 @@ def _read(
729729
glob = kwds.get("glob", None)
730730
files = iterdir(filepath_or_buffer, extensions, glob)
731731

732-
if len(files) == 0:
732+
if isinstance(files, list) and not files:
733733
raise FileNotFoundError(
734734
f"No files found in {filepath_or_buffer}, "
735735
f"with extension(s) {extensions} and glob pattern {glob}"
736736
)
737-
elif len(files) == 1:
738-
parser = TextFileReader(files[0], **kwds)
737+
738+
if (isinstance(files, list) and len(files) == 1) or not isinstance(files, list):
739+
file = files[0] if isinstance(files, list) else files
740+
parser = TextFileReader(file, **kwds)
739741

740742
if chunksize or iterator:
741743
return parser
742744

743745
with parser:
744746
return parser.read(nrows)
745-
else:
746-
return _multi_file_generator(files, kwds)
747+
return _multi_file_generator(files, kwds)
747748

748749

749750
@overload

0 commit comments

Comments
 (0)