Skip to content

Commit 7355c35

Browse files
authored
Allow pathlib.Path to be passed to all engines (#4701)
* Allow pathlib.Path to be used in open_dataset * Fix mypy run. It doesn't like isinstance with os.PathLike * Add patlib.Path support to netCDF4 * Sympler code * Move os.fspath down the call tree
1 parent 20d51cc commit 7355c35

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

xarray/backends/netCDF4_.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import functools
22
import operator
3+
import os
4+
import pathlib
35
from contextlib import suppress
46

57
import numpy as np
@@ -335,6 +337,9 @@ def open(
335337
):
336338
import netCDF4
337339

340+
if isinstance(filename, pathlib.Path):
341+
filename = os.fspath(filename)
342+
338343
if not isinstance(filename, str):
339344
raise ValueError(
340345
"can only read bytes or file-like objects "

xarray/backends/zarr.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import os
2+
import pathlib
3+
14
import numpy as np
25

36
from .. import coding, conventions
@@ -284,6 +287,10 @@ def open_group(
284287
):
285288
import zarr
286289

290+
# zarr doesn't support pathlib.Path objects yet. zarr-python#601
291+
if isinstance(store, pathlib.Path):
292+
store = os.fspath(store)
293+
287294
open_kwargs = dict(mode=mode, synchronizer=synchronizer, path=group)
288295
if chunk_store:
289296
open_kwargs["chunk_store"] = chunk_store

0 commit comments

Comments
 (0)