From 8082e20ba14c12eb501cf438e59bb8df509bbfc4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 6 Dec 2024 21:39:51 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- reciprocalspaceship/dataset.py | 22 ++++++++++++---------- tests/test_dataset.py | 24 +++++++++++++----------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/reciprocalspaceship/dataset.py b/reciprocalspaceship/dataset.py index 408df066..c2433548 100644 --- a/reciprocalspaceship/dataset.py +++ b/reciprocalspaceship/dataset.py @@ -53,7 +53,7 @@ class DataSet(pd.DataFrame): centrics : rs.DataSet Access only the centric reflections in this dataset hkls : ndarray, shape=(n_reflections, 3) - Miller indices in DataSet. + Miller indices in DataSet. merged : bool Whether this is a merged dataset or unmerged @@ -157,27 +157,29 @@ def hkls(self): return hkl def get_hkls(self): - """ For backwards compatibility retain the get_hkls method in addition to the dataset.hkls attribute """ + """For backwards compatibility retain the get_hkls method in addition to the dataset.hkls attribute""" return self.hkls @hkls.setter @range_indexed def hkls(self, hkls): if isinstance(hkls, DataSet): - """ Convert to numpy if hkls is a dataset """ + """Convert to numpy if hkls is a dataset""" hkls = hkls.hkls if isinstance(hkls, np.ndarray): - h,k,l = hkls[...,0], hkls[...,1], hkls[...,2] + h, k, l = hkls[..., 0], hkls[..., 1], hkls[..., 2] else: - """ Try coercing to numpy """ + """Try coercing to numpy""" try: hkls = np.array(hkls) - h,k,l = hkls[...,0], hkls[...,1], hkls[...,2] + h, k, l = hkls[..., 0], hkls[..., 1], hkls[..., 2] except: - raise ValueError("Unable to convert hkls to a suitable type. Please ensure hkls is a numpy array or rs.DataSet") - self['H'] = DataSeries(h, index = self.index, dtype='H') - self['K'] = DataSeries(k, index = self.index, dtype='H') - self['L'] = DataSeries(l, index = self.index, dtype='H') + raise ValueError( + "Unable to convert hkls to a suitable type. Please ensure hkls is a numpy array or rs.DataSet" + ) + self["H"] = DataSeries(h, index=self.index, dtype="H") + self["K"] = DataSeries(k, index=self.index, dtype="H") + self["L"] = DataSeries(l, index=self.index, dtype="H") @property def centrics(self): diff --git a/tests/test_dataset.py b/tests/test_dataset.py index d47d8e28..d202b00b 100644 --- a/tests/test_dataset.py +++ b/tests/test_dataset.py @@ -716,7 +716,9 @@ def test_select_mtzdtype_ValueError(data_merged, dtype): @pytest.mark.parametrize("merged", [True, False]) @pytest.mark.parametrize("hkl_as_ds", [True, False]) @pytest.mark.parametrize("range_index", [True, False]) -def test_hkls_property_setter(data_merged, data_unmerged, merged, hkl_as_ds, range_index): +def test_hkls_property_setter( + data_merged, data_unmerged, merged, hkl_as_ds, range_index +): """ Test the setter for the .hkls property of rs datasets """ @@ -733,20 +735,20 @@ def test_hkls_property_setter(data_merged, data_unmerged, merged, hkl_as_ds, ran hmax = 20 n = len(ds) - hkls = np.random.randint(-hmax, hmax+1, size=(n, 3)) + hkls = np.random.randint(-hmax, hmax + 1, size=(n, 3)) if hkl_as_ds: - hkls = rs.DataSet({ - 'H' : hkls[...,0], - 'K' : hkls[...,1], - 'L' : hkls[...,2], - }) - + hkls = rs.DataSet( + { + "H": hkls[..., 0], + "K": hkls[..., 1], + "L": hkls[..., 2], + } + ) + ds.hkls = hkls assert np.array_equal(hkls, ds.hkls) # Test that all data remained the same for k in input_ds: - if k not in ['H', 'K', 'L']: + if k not in ["H", "K", "L"]: assert np.array_equal(ds[k], input_ds[k]) - -