Skip to content

Commit

Permalink
Address xarray deprecation warnings
Browse files Browse the repository at this point in the history
Fixed DeprecationWarning: Using a DataArray object to construct a variable is ambiguous, please extract the data using the .data property. This will raise a TypeError in 0.19.0.
  • Loading branch information
jsnel committed Jun 27, 2021
1 parent 6c38802 commit 0d301cd
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions glotaran/analysis/problem_ungrouped.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def _add_index_dependent_matrix_to_dataset(self, label: str, dataset: xr.Dataset
(model_dimension),
("clp_label"),
),
matrix,
matrix.data,
)

def _add_index_independent_matrix_to_dataset(self, label: str, dataset: xr.Dataset):
Expand All @@ -218,7 +218,7 @@ def _add_index_independent_matrix_to_dataset(self, label: str, dataset: xr.Datas
(model_dimension),
("clp_label"),
),
self.matrices[label],
self.matrices[label].data,
)

def _add_residual_and_full_clp_to_dataset(self, label: str, dataset: xr.Dataset):
Expand All @@ -230,14 +230,14 @@ def _add_residual_and_full_clp_to_dataset(self, label: str, dataset: xr.Dataset)
(model_dimension),
(global_dimension),
),
xr.concat(self.weighted_residuals[label], dim=global_dimension).T,
xr.concat(self.weighted_residuals[label], dim=global_dimension).T.data,
)
dataset["residual"] = (
(
(model_dimension),
(global_dimension),
),
xr.concat(self.residuals[label], dim=global_dimension).T,
xr.concat(self.residuals[label], dim=global_dimension).T.data,
)

@property
Expand Down
4 changes: 2 additions & 2 deletions glotaran/analysis/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def simulate(
result = xr.DataArray(
data=0.0,
coords=[
(model_dimension, model_axis),
(global_dimension, global_axis),
(model_dimension, model_axis.data),
(global_dimension, global_axis.data),
],
)
result = result.to_dataset(name="data")
Expand Down
4 changes: 2 additions & 2 deletions glotaran/analysis/test/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def calculate_matrix(self, dataset_model, indices, **kwargs):
r_compartments.append(compartments[i])
for j in range(axis.shape[0]):
array[j, i] = (i + j) * axis[j]
return xr.DataArray(array, coords=(("c", axis), ("clp_label", r_compartments)))
return xr.DataArray(array, coords=(("c", axis.data), ("clp_label", r_compartments)))

def index_dependent(self, dataset_model):
return self.is_index_dependent
Expand Down Expand Up @@ -75,7 +75,7 @@ def calculate_matrix(self, dataset_model, indices, **kwargs):
else:
compartments = [f"s{i+1}" for i in range(len(kinpar))]
array = np.exp(np.outer(axis, kinpar))
return xr.DataArray(array, coords=(("c", axis), ("clp_label", compartments)))
return xr.DataArray(array, coords=(("c", axis.data), ("clp_label", compartments)))

def index_dependent(self, dataset_model):
return self.is_index_dependent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def calculate_matrix(
compartments = [f"{dataset_model.label}_baseline"]
matrix = np.ones((model_axis.size, 1), dtype=np.float64)
return xr.DataArray(
matrix, coords=((model_dimension, model_axis), ("clp_label", compartments))
matrix, coords=((model_dimension, model_axis.data), ("clp_label", compartments))
)

def index_dependent(self, dataset: DatasetDescriptor) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion glotaran/builtin/models/spectral/spectral_megacomplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def calculate_matrix(
for i, shape in enumerate(self.shape.values()):
matrix[:, i] += shape.calculate(model_axis.values)
return xr.DataArray(
matrix, coords=((model_dimension, model_axis), ("clp_label", compartments))
matrix, coords=((model_dimension, model_axis.data), ("clp_label", compartments))
)

def index_dependent(self, dataset: DatasetDescriptor) -> bool:
Expand Down
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ envlist = py{38}, pre-commit, docs, docs-notebooks, docs-links
; Uncomment the following lines to deactivate pyglotaran all plugins
; env =
; DEACTIVATE_GTA_PLUGINS=1
; Uncomment to ignore deprecation warnings coming from pyglotaran
; (this helps to see the warnings from dependencies)
; filterwarnings =
; ignore:.+glotaran:DeprecationWarning

[flake8]
extend-ignore = E231, E203
Expand Down

0 comments on commit 0d301cd

Please sign in to comment.