22from glob import glob
33from io import BytesIO
44from numbers import Number
5- from pathlib import Path
65from typing import (
76 TYPE_CHECKING ,
87 Callable ,
@@ -808,7 +807,7 @@ def open_mfdataset(
808807 - "override": if indexes are of same size, rewrite indexes to be
809808 those of the first object with that dimension. Indexes for the same
810809 dimension must have the same size in all objects.
811- attrs_file : str or pathlib.Path , optional
810+ attrs_file : str or path-like , optional
812811 Path of the file used to read global attributes from.
813812 By default global attributes are read from the first file provided,
814813 with wildcard matches sorted by filename.
@@ -866,7 +865,7 @@ def open_mfdataset(
866865 else :
867866 paths = sorted (glob (_normalize_path (paths )))
868867 else :
869- paths = [str (p ) if isinstance (p , Path ) else p for p in paths ]
868+ paths = [os . fspath (p ) if isinstance (p , os . PathLike ) else p for p in paths ]
870869
871870 if not paths :
872871 raise OSError ("no files to open" )
@@ -958,8 +957,8 @@ def multi_file_closer():
958957
959958 # read global attributes from the attrs_file or from the first dataset
960959 if attrs_file is not None :
961- if isinstance (attrs_file , Path ):
962- attrs_file = str (attrs_file )
960+ if isinstance (attrs_file , os . PathLike ):
961+ attrs_file = os . fspath (attrs_file )
963962 combined .attrs = datasets [paths .index (attrs_file )].attrs
964963
965964 return combined
@@ -992,8 +991,8 @@ def to_netcdf(
992991
993992 The ``multifile`` argument is only for the private use of save_mfdataset.
994993 """
995- if isinstance (path_or_file , Path ):
996- path_or_file = str (path_or_file )
994+ if isinstance (path_or_file , os . PathLike ):
995+ path_or_file = os . fspath (path_or_file )
997996
998997 if encoding is None :
999998 encoding = {}
@@ -1134,7 +1133,7 @@ def save_mfdataset(
11341133 ----------
11351134 datasets : list of Dataset
11361135 List of datasets to save.
1137- paths : list of str or list of Path
1136+ paths : list of str or list of path-like objects
11381137 List of paths to which to save each corresponding dataset.
11391138 mode : {"w", "a"}, optional
11401139 Write ("w") or append ("a") mode. If mode="w", any existing file at
@@ -1302,7 +1301,7 @@ def check_dtype(var):
13021301
13031302def to_zarr (
13041303 dataset : Dataset ,
1305- store : Union [MutableMapping , str , Path ] = None ,
1304+ store : Union [MutableMapping , str , os . PathLike ] = None ,
13061305 chunk_store = None ,
13071306 mode : str = None ,
13081307 synchronizer = None ,
@@ -1326,7 +1325,7 @@ def to_zarr(
13261325 if v .size == 0 :
13271326 v .load ()
13281327
1329- # expand str and Path arguments
1328+ # expand str and path-like arguments
13301329 store = _normalize_path (store )
13311330 chunk_store = _normalize_path (chunk_store )
13321331
0 commit comments