diff --git a/src/biotite/structure/atoms.py b/src/biotite/structure/atoms.py index 2245e0cfa..0be02e172 100644 --- a/src/biotite/structure/atoms.py +++ b/src/biotite/structure/atoms.py @@ -233,7 +233,7 @@ def _del_element(self, index): else: raise TypeError(f"Index must be integer, not '{type(index).__name__}'") - def equal_annotations(self, item): + def equal_annotations(self, item, equal_nan=True): """ Check, if this object shares equal annotation arrays with the given :class:`AtomArray` or :class:`AtomArrayStack`. @@ -242,6 +242,8 @@ def equal_annotations(self, item): ---------- item : AtomArray or AtomArrayStack The object to compare the annotation arrays with. + equal_nan: bool + Whether to count `nan` values as equal. Default: True. Returns ------- @@ -253,7 +255,18 @@ def equal_annotations(self, item): if not self.equal_annotation_categories(item): return False for name in self._annot: - if not np.array_equal(self._annot[name], item._annot[name]): + # ... allowing `nan` values causes type-casting, which is + # only possible for floating-point arrays + allow_nan = ( + equal_nan + if np.issubdtype(self._annot[name].dtype, np.floating) + else False + ) + if not np.array_equal( + self._annot[name], + item._annot[name], + equal_nan=allow_nan, + ): return False return True