Skip to content

Commit

Permalink
Replace deprecated inplace methods in xarray.
Browse files Browse the repository at this point in the history
In xarray 0.11.0 several inplace methods are deprecated and will be
removed in 0.12.0: pydata/xarray#1756
  • Loading branch information
lkluft committed Nov 14, 2018
1 parent 4084e61 commit 70fc6ec
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions typhon/collocations/collocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ def _flat_to_main_coord(data):
data["collocation"] = shared_dims[0], np.arange(
data[shared_dims[0]].size)
data = data.swap_dims({shared_dims[0]: "collocation"})
data.reset_coords(shared_dims[0], inplace=True)
data = data.reset_coords(shared_dims[0])

# So far, collocation is a coordinate. We want to make it to a
# dimension, so drop its values:
Expand Down Expand Up @@ -1046,7 +1046,7 @@ def _flat_to_main_coord(data):
# for dim in dims:
# new_dim = f"__replacement_{dim}"
# data[new_dim] = dim, np.arange(data.dims[dim])
# data.swap_dims({dim: new_dim}, inplace=True)
# data = data.swap_dims({dim: new_dim})
# new_dims.append(new_dim)
return data.stack(collocation=dims)

Expand Down
9 changes: 3 additions & 6 deletions typhon/collocations/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,16 +462,13 @@ def expand(dataset):
for i in range(2):
expanded["collocation"] = groups[i] + "/collocation", \
np.arange(pairs[i].size)
expanded.swap_dims(
{groups[i] + "/collocation": "collocation"}, inplace=True
expanded = expanded.swap_dims(
{groups[i] + "/collocation": "collocation"}
)

# The variable pairs is useless now:
expanded = expanded.drop("Collocations/pairs")

expanded.rename(
{"Collocations/collocation": "collocation"},
inplace=True
)
expanded = expanded.rename({"Collocations/collocation": "collocation"})

return expanded
2 changes: 1 addition & 1 deletion typhon/files/handlers/cloudsat.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def read(self, file_info, **kwargs):
)

if user_mapping is not None:
dataset.rename(user_mapping, inplace=True)
dataset = dataset.rename(user_mapping)

return dataset

Expand Down
6 changes: 3 additions & 3 deletions typhon/files/handlers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _xarray_rename_fields(dataset, mapping):
if old_name in names
}

dataset.rename(mapping, inplace=True)
dataset = dataset.rename(mapping)

return dataset

Expand Down Expand Up @@ -786,12 +786,12 @@ def write(self, data, filename, **kwargs):
full: NetCDF4._split_path(full)[1]
for full in ds.data_vars
}
ds.rename(mapping, inplace=True)
ds = ds.rename(mapping)
mapping = {
dim: NetCDF4._split_path(dim)[1]
for dim in ds.dims
}
ds.rename(mapping, inplace=True)
ds = ds.rename(mapping)

ds.to_netcdf(
filename.path, group=group,
Expand Down
2 changes: 1 addition & 1 deletion typhon/files/handlers/meteosat.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def read(self, file_info, fields=None, calibration=True, **kwargs):
for old, new in self.channel_names.items()
if old in dataset.variables
}
dataset.rename(mapping, inplace=True)
dataset = dataset.rename(mapping)
return dataset

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions typhon/files/handlers/tovs.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def read(self, file_info, mask_and_scale=True, **kwargs):
check_lat_lon(dataset)

if user_mapping is not None:
dataset.rename(user_mapping, inplace=True)
dataset = dataset.rename(user_mapping)

return dataset

Expand Down Expand Up @@ -289,7 +289,7 @@ def read(self, file_info, mask_and_scale=True, interpolate_packed_pixels=True,
check_lat_lon(dataset)

if user_mapping is not None:
dataset.rename(user_mapping, inplace=True)
dataset = dataset.rename(user_mapping)

return dataset

Expand Down

0 comments on commit 70fc6ec

Please sign in to comment.