Skip to content

Commit 4df36da

Browse files
committed
Remove keep_attrs keywords
1 parent 9512d13 commit 4df36da

File tree

4 files changed

+10
-29
lines changed

4 files changed

+10
-29
lines changed

xarray/core/dataarray.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ def reindex(self, indexers=None, method=None, tolerance=None, copy=True,
907907
return self._from_temp_dataset(ds)
908908

909909
def interp(self, coords=None, method='linear', assume_sorted=False,
910-
keep_attrs=False, kwargs={}, **coords_kwargs):
910+
kwargs={}, **coords_kwargs):
911911
""" Multidimensional interpolation of variables.
912912
913913
coords : dict, optional
@@ -922,10 +922,6 @@ def interp(self, coords=None, method='linear', assume_sorted=False,
922922
If False, values of x can be in any order and they are sorted
923923
first. If True, x has to be an array of monotonically increasing
924924
values.
925-
keep_attrs : bool, optional
926-
If True, the variable's attributes (`attrs`) will be copied from
927-
the original object to the new one. If False (default), the new
928-
object will be returned without attributes.
929925
kwargs: dictionary
930926
Additional keyword passed to scipy's interpolator.
931927
**coords_kwarg : {dim: coordinate, ...}, optional
@@ -952,7 +948,7 @@ def interp(self, coords=None, method='linear', assume_sorted=False,
952948

953949
ds = self._to_temp_dataset().interp(
954950
coords, method=method, kwargs=kwargs, assume_sorted=assume_sorted,
955-
keep_attrs=keep_attrs, **coords_kwargs)
951+
**coords_kwargs)
956952
return self._from_temp_dataset(ds)
957953

958954
def rename(self, new_name_or_name_dict=None, **names):

xarray/core/dataset.py

+5-13
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ def reindex(self, indexers=None, method=None, tolerance=None, copy=True,
18151815
return self._replace_vars_and_dims(variables, coord_names)
18161816

18171817
def interp(self, coords=None, method='linear', assume_sorted=False,
1818-
keep_attrs=False, kwargs={}, **coords_kwargs):
1818+
kwargs={}, **coords_kwargs):
18191819
""" Multidimensional interpolation of Dataset.
18201820
18211821
Parameters
@@ -1834,10 +1834,6 @@ def interp(self, coords=None, method='linear', assume_sorted=False,
18341834
in any order and they are sorted first. If True, interpolated
18351835
coordinates are assumed to be an array of monotonically increasing
18361836
values.
1837-
keep_attrs : bool, optional
1838-
If True, the dataset's attributes (`attrs`) will be copied from
1839-
the original object to the new one. If False (default), the new
1840-
object will be returned without attributes.
18411837
kwargs: dictionary, optional
18421838
Additional keyword passed to scipy's interpolator.
18431839
**coords_kwarg : {dim: coordinate, ...}, optional
@@ -1879,15 +1875,14 @@ def maybe_variable(obj, k):
18791875
var_indexers = {k: (maybe_variable(obj, k), v) for k, v
18801876
in indexers.items() if k in var.dims}
18811877
variables[name] = missing.interp(
1882-
var, var_indexers, method, keep_attrs, **kwargs)
1878+
var, var_indexers, method, **kwargs)
18831879
elif all(d not in indexers for d in var.dims):
18841880
# keep unrelated object array
18851881
variables[name] = var
18861882

18871883
coord_names = set(variables).intersection(obj._coord_names)
1888-
1889-
selected = obj._replace_vars_and_dims(
1890-
variables, coord_names=coord_names)
1884+
selected = obj._replace_vars_and_dims(variables,
1885+
coord_names=coord_names)
18911886
# attach indexer as coordinate
18921887
variables.update(indexers)
18931888
# Extract coordinates from indexers
@@ -1896,10 +1891,7 @@ def maybe_variable(obj, k):
18961891
coord_names = (set(variables)
18971892
.intersection(obj._coord_names)
18981893
.union(coord_vars))
1899-
1900-
attrs = self.attrs if keep_attrs else None
1901-
return obj._replace_vars_and_dims(
1902-
variables, coord_names=coord_names, attrs=attrs)
1894+
return obj._replace_vars_and_dims(variables, coord_names=coord_names)
19031895

19041896
def rename(self, name_dict=None, inplace=False, **names):
19051897
"""Returns a new object with renamed variables and dimensions.

xarray/core/missing.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def _localize(var, indexes_coords):
394394
return var.isel(**indexes), indexes_coords
395395

396396

397-
def interp(var, indexes_coords, method, keep_attrs, **kwargs):
397+
def interp(var, indexes_coords, method, **kwargs):
398398
""" Make an interpolation of Variable
399399
400400
Parameters
@@ -408,8 +408,6 @@ def interp(var, indexes_coords, method, keep_attrs, **kwargs):
408408
One of {'linear', 'nearest', 'zero', 'slinear', 'quadratic',
409409
'cubic'}. For multidimensional interpolation, only
410410
{'linear', 'nearest'} can be used.
411-
keep_attrs: boolean
412-
If True, variable's attributes (`attrs`) will be copied
413411
**kwargs:
414412
keyword arguments to be passed to scipy.interpolate
415413
@@ -444,8 +442,7 @@ def interp(var, indexes_coords, method, keep_attrs, **kwargs):
444442
interped = interp_func(var.transpose(*original_dims).data,
445443
x, destination, method, kwargs)
446444

447-
attrs = var.attrs if keep_attrs else {}
448-
result = Variable(new_dims, interped, attrs=attrs)
445+
result = Variable(new_dims, interped, attrs=var.attrs)
449446

450447
# dimension of the output array
451448
out_dims = OrderedSet()

xarray/tests/test_interp.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,7 @@ def test_dataset():
377377

378378
assert not interpolated['var1'].equals(ds['var1'])
379379
assert not interpolated['var3'].equals(ds['var3'])
380-
# attrs should not be tracked
381-
assert 'foo' not in interpolated.attrs
382-
assert 'buz' not in interpolated['var1'].attrs
383-
384-
interpolated = ds.interp(dim2=new_dim2, keep_attrs=True)
380+
# attrs should be kept
385381
assert interpolated.attrs['foo'] == 'var'
386382
assert interpolated['var1'].attrs['buz'] == 'var2'
387383

0 commit comments

Comments
 (0)