Skip to content

Commit aae32a8

Browse files
committed
Use pathlib w DataArray.to_netcdf
1 parent 3ca8c9e commit aae32a8

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

xarray/backends/api.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ def open_dataset(filename_or_obj, group=None, decode_cf=True,
145145
Parameters
146146
----------
147147
filename_or_obj : str, Path, file or xarray.backends.*DataStore
148-
Strings and Path objects are interpreted as a path to a netCDF file oran OpenDAP URL
149-
and opened with python-netCDF4, unless the filename ends with .gz, in
150-
which case the file is gunzipped and opened with scipy.io.netcdf (only
151-
netCDF3 supported). File-like objects are opened with scipy.io.netcdf
152-
(only netCDF3 supported).
148+
Strings and Path objects are interpreted as a path to a netCDF file
149+
oran OpenDAP URL and opened with python-netCDF4, unless the filename
150+
ends with .gz, in which case the file is gunzipped and opened with
151+
scipy.io.netcdf (only netCDF3 supported). File-like objects are opened
152+
with scipy.io.netcdf (only netCDF3 supported).
153153
group : str, optional
154154
Path to the netCDF4 group in the given file to open (only works for
155155
netCDF4 files).
@@ -325,12 +325,12 @@ def open_dataarray(*args, **kwargs):
325325
326326
Parameters
327327
----------
328-
filename_or_obj : str, file or xarray.backends.*DataStore
329-
Strings are interpreted as a path to a netCDF file or an OpenDAP URL
330-
and opened with python-netCDF4, unless the filename ends with .gz, in
331-
which case the file is gunzipped and opened with scipy.io.netcdf (only
332-
netCDF3 supported). File-like objects are opened with scipy.io.netcdf
333-
(only netCDF3 supported).
328+
filename_or_obj : str, Path, file or xarray.backends.*DataStore
329+
Strings and Paths are interpreted as a path to a netCDF file or an
330+
OpenDAP URL and opened with python-netCDF4, unless the filename ends
331+
with .gz, in which case the file is gunzipped and opened with
332+
scipy.io.netcdf (only netCDF3 supported). File-like objects are opened
333+
with scipy.io.netcdf (only netCDF3 supported).
334334
group : str, optional
335335
Path to the netCDF4 group in the given file to open (only works for
336336
netCDF4 files).
@@ -445,7 +445,8 @@ def open_mfdataset(paths, chunks=None, concat_dim=_CONCAT_DIM_DEFAULT,
445445
----------
446446
paths : str or sequence
447447
Either a string glob in the form "path/to/my/files/*.nc" or an explicit
448-
list of files to open. Paths can be given as strings or as pathlib Paths.
448+
list of files to open. Paths can be given as strings or as pathlib
449+
Paths.
449450
chunks : int or dict, optional
450451
Dictionary with keys given by dimension names and values given by chunk
451452
sizes. In general, these should divide the dimensions of each dataset.

xarray/tests/test_backends.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,3 +1963,13 @@ def test_open_dataarray_options(self):
19631963
expected = data.drop('y')
19641964
with open_dataarray(tmp, drop_variables=['y']) as loaded:
19651965
self.assertDataArrayIdentical(expected, loaded)
1966+
1967+
def test_dataarray_to_netcdf_no_name_pathlib(self):
1968+
original_da = DataArray(np.arange(12).reshape((3, 4)))
1969+
1970+
with create_tmp_file() as tmp:
1971+
tmp = Path(tmp)
1972+
original_da.to_netcdf(tmp)
1973+
1974+
with open_dataarray(tmp) as loaded_da:
1975+
self.assertDataArrayIdentical(original_da, loaded_da)

0 commit comments

Comments
 (0)