diff --git a/reciprocalspaceship/concat.py b/reciprocalspaceship/concat.py index 76fb4888..42804499 100644 --- a/reciprocalspaceship/concat.py +++ b/reciprocalspaceship/concat.py @@ -27,10 +27,6 @@ def concat(*args, check_isomorphous=True, **kwargs): rs.DataSet or rs.DataSeries Returns rs.DataSeries when concatenating rs.DataSeries along the index (axis=0). Returns rs.DataSet in all other cases. - - See Also - -------- - DataSet.append : Concatenate DataSets """ objs = kwargs.get("objs", args[0]) objs, objs_tee = tee(objs) diff --git a/reciprocalspaceship/dataset.py b/reciprocalspaceship/dataset.py index cc23c6ba..60dfc57f 100644 --- a/reciprocalspaceship/dataset.py +++ b/reciprocalspaceship/dataset.py @@ -3,7 +3,7 @@ import pandas as pd from pandas.api.types import is_complex_dtype -from reciprocalspaceship import dtypes +from reciprocalspaceship import concat, dtypes from reciprocalspaceship.dataseries import DataSeries from reciprocalspaceship.decorators import ( cellify, @@ -404,50 +404,6 @@ def from_structurefactor(self, sf_key): """ return from_structurefactor(self[sf_key]) - def append(self, *args, check_isomorphous=True, **kwargs): - """ - Append rows of `other` to the end of calling DataSet, returning - a new DataSet object. Any columns in `other` that are not present - in the calling DataSet are added as new columns. - - For additional documentation on accepted arguments, see the - `Pandas DataFrame.append() API `_. - - Parameters - ---------- - check_isomorphous : bool - If True, the spacegroup and cell attributes of DataSets in `other` - will be compared to those of the calling DataSet to ensure - they are isomorphous. - - Returns - ------- - rs.DataSet - - See Also - -------- - concat : Concatenate ``rs`` objects - """ - other = kwargs.get("other", args[0]) - if check_isomorphous: - if isinstance(other, (list, tuple)): - for o in other: - if isinstance(o, DataSet) and not self.is_isomorphous(o): - raise ValueError("DataSet in `other` is not isomorphous") - else: - if isinstance(other, DataSet) and not self.is_isomorphous(other): - raise ValueError("`other` DataSet is not isomorphous") - result = super().append(*args, **kwargs) - - # If `ignore_index=True`, the _index_dtypes attribute should - # be reset. - if isinstance(result.index, pd.RangeIndex) and self._index_dtypes != {}: - result.__finalize__(self) - result._index_dtypes = {} - return result - - return result.__finalize__(self) - def merge(self, *args, check_isomorphous=True, **kwargs): """ Merge DataSet or named DataSeries using a database-style join on @@ -912,7 +868,7 @@ def stack_anomalous( column_mapping_minus = dict(zip(minus_labels, new_labels)) dataset_plus.rename(columns=column_mapping_plus, inplace=True) dataset_minus.rename(columns=column_mapping_minus, inplace=True) - F = dataset_plus.append(dataset_minus) + F = concat([dataset_plus, dataset_minus]) for label in new_labels: F[label] = F[label].from_friedel_dtype() @@ -1216,7 +1172,7 @@ def expand_to_p1(self): ds = self.copy() ds["M/ISYM"] = isym ds["M/ISYM"] = ds["M/ISYM"].astype("M/ISYM") - p1 = p1.append(ds.hkl_to_observed(m_isym="M/ISYM")) + p1 = concat([p1, ds.hkl_to_observed(m_isym="M/ISYM")]) p1.drop_duplicates(subset=["H", "K", "L"], inplace=True) # Restrict to p1 ASU @@ -1236,7 +1192,7 @@ def expand_anomalous(self): DataSet """ friedel = self.apply_symop("-x,-y,-z") - return self.append(friedel) + return concat([self, friedel]) @inplace def canonicalize_phases(self, inplace=False): diff --git a/reciprocalspaceship/utils/stats.py b/reciprocalspaceship/utils/stats.py index d3425029..2243270a 100644 --- a/reciprocalspaceship/utils/stats.py +++ b/reciprocalspaceship/utils/stats.py @@ -77,7 +77,7 @@ def compute_redundancy( spacegroup=spacegroup, ).set_index(["H", "K", "L"]) ASU = ASU.loc[ASU.index.difference(mult.index)] - mult = mult.append(ASU) + mult = rs.concat([mult, ASU]) mult = mult.sort_index() return mult.get_hkls(), mult["Count"].to_numpy(np.int32) diff --git a/tests/test_dataset_preserve_attributes.py b/tests/test_dataset_preserve_attributes.py index 17a45859..f670ed60 100644 --- a/tests/test_dataset_preserve_attributes.py +++ b/tests/test_dataset_preserve_attributes.py @@ -37,65 +37,6 @@ def test_concat(data_fmodel, check_isomorphous, sg, ignore_index): assert result.__getattr__(attr) == data_fmodel.__getattr__(attr) -@pytest.mark.parametrize("check_isomorphous", [True, False]) -@pytest.mark.parametrize("sg", [gemmi.SpaceGroup(19), gemmi.SpaceGroup(96)]) -@pytest.mark.parametrize("ignore_index", [True, False]) -def test_append(data_fmodel, check_isomorphous, sg, ignore_index): - """ - Test whether attributes of DataSet are preserved through calls to - DataSet.append() - """ - other = data_fmodel.copy(deep=True) - other.spacegroup = sg - if check_isomorphous and sg.number == 19: - with pytest.raises(ValueError): - result = data_fmodel.append( - other, ignore_index, check_isomorphous=check_isomorphous - ) - else: - result = data_fmodel.append( - other, ignore_index, check_isomorphous=check_isomorphous - ) - assert isinstance(result, rs.DataSet) - assert len(result) == len(data_fmodel) * 2 - if ignore_index: - assert result._index_dtypes == {} - for attr in data_fmodel._metadata: - if attr == "_index_dtypes": - continue - assert result.__getattr__(attr) == data_fmodel.__getattr__(attr) - - -@pytest.mark.parametrize("check_isomorphous", [True, False]) -@pytest.mark.parametrize("sg", [gemmi.SpaceGroup(19), gemmi.SpaceGroup(96)]) -@pytest.mark.parametrize("ignore_index", [True, False]) -def test_append_list(data_fmodel, check_isomorphous, sg, ignore_index): - """ - Test whether attributes of DataSet are preserved through calls to - DataSet.append() using a list for `other` argument - """ - other = data_fmodel.copy(deep=True) - other.spacegroup = sg - other = [other] * 3 - if check_isomorphous and sg.number == 19: - with pytest.raises(ValueError): - result = data_fmodel.append( - other, ignore_index, check_isomorphous=check_isomorphous - ) - else: - result = data_fmodel.append( - other, ignore_index, check_isomorphous=check_isomorphous - ) - assert isinstance(result, rs.DataSet) - assert len(result) == len(data_fmodel) * 4 - if ignore_index: - assert result._index_dtypes == {} - for attr in data_fmodel._metadata: - if attr == "_index_dtypes": - continue - assert result.__getattr__(attr) == data_fmodel.__getattr__(attr) - - @pytest.mark.parametrize("check_isomorphous", [True, False]) @pytest.mark.parametrize("sg", [gemmi.SpaceGroup(19), gemmi.SpaceGroup(96)]) def test_merge(data_fmodel, check_isomorphous, sg):