Skip to content

Commit 598ab4d

Browse files
committed
support PathLikes in fromcdl
1 parent b04f3ad commit 598ab4d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/netCDF4/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ class Dataset:
373373
def get_variables_by_attributes(self, **kwargs: Callable[[Any], bool] | Any) -> list[Variable]: ...
374374
@staticmethod
375375
def fromcdl(
376-
cdlfilename: str, ncfilename: str | None = None, mode: AccessMode = "a", format: Format = "NETCDF4"
376+
cdlfilename: str | os.PathLike, ncfilename: str | os.PathLike | None = None, mode: AccessMode = "a", format: Format = "NETCDF4"
377377
) -> Dataset: ...
378378
@overload
379379
def tocdl(self, coordvars: bool = False, data: bool = False, outfile: None = None) -> str: ...

src/netCDF4/_netCDF4.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3502,8 +3502,8 @@ Dataset instance for `ncfilename` is returned.
35023502
[ncgen]: https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#ncgen_guide
35033503
[cdl]: https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#cdl_guide
35043504
"""
3505+
filepath = pathlib.Path(cdlfilename)
35053506
if ncfilename is None:
3506-
filepath = pathlib.Path(cdlfilename)
35073507
ncfilename = filepath.with_suffix('.nc')
35083508
formatcodes = {'NETCDF4': 4,
35093509
'NETCDF4_CLASSIC': 7,
@@ -3514,7 +3514,7 @@ Dataset instance for `ncfilename` is returned.
35143514
if format not in formatcodes:
35153515
raise ValueError('illegal format requested')
35163516
ncgenargs="-knc%s" % formatcodes[format]
3517-
subprocess.run(["ncgen", ncgenargs, "-o", ncfilename, cdlfilename], check=True)
3517+
subprocess.run(["ncgen", ncgenargs, "-o", str(ncfilename), str(cdlfilename)], check=True)
35183518
return Dataset(ncfilename, mode=mode)
35193519

35203520
def tocdl(self,coordvars=False,data=False,outfile=None):

0 commit comments

Comments
 (0)