Skip to content

Commit e98b4df

Browse files
committed
Handle single PathLike objects in open_mfdataset()
Fixes #5881
1 parent 07de257 commit e98b4df

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

xarray/backends/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,8 @@ def open_mfdataset(
865865
)
866866
else:
867867
paths = sorted(glob(_normalize_path(paths)))
868+
elif isinstance(paths, os.PathLike):
869+
paths = [os.fspath(paths)]
868870
else:
869871
paths = [str(p) if isinstance(p, Path) else p for p in paths]
870872

xarray/tests/test_backends.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3039,6 +3039,14 @@ def test_open_mfdataset_manyfiles(
30393039
assert_identical(original, actual)
30403040

30413041

3042+
@requires_netCDF4
3043+
@requires_dask
3044+
def test_open_mfdataset_can_open_path_objects():
3045+
dataset = os.path.join(os.path.dirname(__file__), "data", "example_1.nc")
3046+
with open_mfdataset(Path(dataset)) as actual:
3047+
assert isinstance(actual, Dataset)
3048+
3049+
30423050
@requires_netCDF4
30433051
@requires_dask
30443052
def test_open_mfdataset_list_attr():

0 commit comments

Comments
 (0)