Skip to content

Commit 9f459c3

Browse files
authored
Fix open_mfdataset for list of fsspec files (#9785)
* Fix open_mfdataset for list of fsspec files * Rewrite to for loop * Fixup
1 parent 864b35a commit 9f459c3

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

xarray/backends/common.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,15 @@ def _find_absolute_paths(
136136
def _normalize_path_list(
137137
lpaths: NestedSequence[str | os.PathLike],
138138
) -> NestedSequence[str]:
139-
return [
140-
(
141-
_normalize_path(p)
142-
if isinstance(p, str | os.PathLike)
143-
else _normalize_path_list(p)
144-
)
145-
for p in lpaths
146-
]
139+
paths = []
140+
for p in lpaths:
141+
if isinstance(p, str | os.PathLike):
142+
paths.append(_normalize_path(p))
143+
elif isinstance(p, list):
144+
paths.append(_normalize_path_list(p)) # type: ignore[arg-type]
145+
else:
146+
paths.append(p) # type: ignore[arg-type]
147+
return paths
147148

148149
return _normalize_path_list(paths)
149150

xarray/tests/test_backends.py

+2
Original file line numberDiff line numberDiff line change
@@ -5511,6 +5511,8 @@ def test_source_encoding_always_present_with_fsspec() -> None:
55115511
fs = fsspec.filesystem("file")
55125512
with fs.open(tmp) as f, open_dataset(f) as ds:
55135513
assert ds.encoding["source"] == tmp
5514+
with fs.open(tmp) as f, open_mfdataset([f]) as ds:
5515+
assert "foo" in ds
55145516

55155517

55165518
def _assert_no_dates_out_of_range_warning(record):

0 commit comments

Comments
 (0)