Skip to content

Commit 49d4f0c

Browse files
committed
validate before replacement
1 parent 193faa7 commit 49d4f0c

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/singlecellexperiment/SingleCellExperiment.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,11 @@ def reduced_dims(self, reduced_dims: Dict[str, Any]):
402402
self.set_reduced_dimensions(reduced_dims, in_place=True)
403403

404404
@property
405-
def reduced_dimensionss(self) -> Dict[str, Any]:
405+
def reduced_dimensions(self) -> Dict[str, Any]:
406406
"""Alias for :py:meth:`~get_reduced_dimensions`."""
407407
return self.get_reduced_dimensions()
408408

409-
@reduced_dimensionss.setter
409+
@reduced_dimensions.setter
410410
def reduced_dimensions(self, reduced_dims: Dict[str, Any]):
411411
"""Alias for :py:meth:`~set_reduced_dimensions`."""
412412
warn(
@@ -543,13 +543,18 @@ def set_reduced_dimension(self, name: str, embedding: Any, in_place: bool = Fals
543543
Whether to modify the ``SingleCellExperiment`` in place.
544544
545545
Returns:
546-
A modified ``BasSingleCellExperimenteSE`` object, either as a copy of the original
546+
A modified ``SingleCellExperiment`` object, either as a copy of the original
547547
or as a reference to the (in-place-modified) original.
548548
"""
549549
output = self._define_output(in_place)
550+
551+
_tmp_red_dims = output._reduced_dims
550552
if in_place is False:
551-
output._reduced_dims = output._reduced_dims.copy()
552-
output._reduced_dims[name] = embedding
553+
_tmp_red_dims = _tmp_red_dims.copy()
554+
_tmp_red_dims[name] = embedding
555+
556+
_validate_reduced_dims(_tmp_red_dims, self._shape)
557+
output._reduced_dims = _tmp_red_dims
553558
return output
554559

555560
################################
@@ -758,9 +763,14 @@ def set_alternative_experiment(
758763
or as a reference to the (in-place-modified) original.
759764
"""
760765
output = self._define_output(in_place)
766+
767+
_tmp_alt_expt = output._alternative_experiments
761768
if in_place is False:
762-
output._alternative_experiments = output._alternative_experiments.copy()
763-
output._alternative_experiments[name] = alternative_experiment
769+
_tmp_alt_expt = _tmp_alt_expt.copy()
770+
_tmp_alt_expt[name] = alternative_experiment
771+
772+
_validate_alternative_experiments(_tmp_alt_expt, self._shape)
773+
output._alternative_experiments = _tmp_alt_expt
764774
return output
765775

766776
###########################

0 commit comments

Comments
 (0)