Skip to content

Allow pathlib.Path to be passed to all engines #4701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions xarray/backends/netCDF4_.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import functools
import operator
import os
import pathlib
from contextlib import suppress

import numpy as np
Expand Down Expand Up @@ -335,6 +337,9 @@ def open(
):
import netCDF4

if isinstance(filename, pathlib.Path):
filename = os.fspath(filename)

if not isinstance(filename, str):
raise ValueError(
"can only read bytes or file-like objects "
Expand Down
7 changes: 7 additions & 0 deletions xarray/backends/zarr.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import pathlib

import numpy as np

from .. import coding, conventions
Expand Down Expand Up @@ -284,6 +287,10 @@ def open_group(
):
import zarr

# zarr doesn't support pathlib.Path objects yet. zarr-python#601
if isinstance(store, pathlib.Path):
store = os.fspath(store)

open_kwargs = dict(mode=mode, synchronizer=synchronizer, path=group)
if chunk_store:
open_kwargs["chunk_store"] = chunk_store
Expand Down