Skip to content

Commit

Permalink
Fix open_mfdataset for list of fsspec files (pydata#9785)
Browse files Browse the repository at this point in the history
* Fix open_mfdataset for list of fsspec files

* Rewrite to for loop

* Fixup
  • Loading branch information
phofl authored Nov 15, 2024
1 parent 864b35a commit 9f459c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 9 additions & 8 deletions xarray/backends/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@ def _find_absolute_paths(
def _normalize_path_list(
lpaths: NestedSequence[str | os.PathLike],
) -> NestedSequence[str]:
return [
(
_normalize_path(p)
if isinstance(p, str | os.PathLike)
else _normalize_path_list(p)
)
for p in lpaths
]
paths = []
for p in lpaths:
if isinstance(p, str | os.PathLike):
paths.append(_normalize_path(p))
elif isinstance(p, list):
paths.append(_normalize_path_list(p)) # type: ignore[arg-type]
else:
paths.append(p) # type: ignore[arg-type]
return paths

return _normalize_path_list(paths)

Expand Down
2 changes: 2 additions & 0 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -5511,6 +5511,8 @@ def test_source_encoding_always_present_with_fsspec() -> None:
fs = fsspec.filesystem("file")
with fs.open(tmp) as f, open_dataset(f) as ds:
assert ds.encoding["source"] == tmp
with fs.open(tmp) as f, open_mfdataset([f]) as ds:
assert "foo" in ds


def _assert_no_dates_out_of_range_warning(record):
Expand Down

0 comments on commit 9f459c3

Please sign in to comment.