From ec963dee63e22f24f02d1fe775f839a6532ab54a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 28 Nov 2024 14:09:03 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sodym/dimensions.py | 6 ++++-- sodym/named_dim_arrays.py | 4 +++- tests/test_named_dim_arrays.py | 12 ++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/sodym/dimensions.py b/sodym/dimensions.py index e69a33b..993fa61 100644 --- a/sodym/dimensions.py +++ b/sodym/dimensions.py @@ -150,8 +150,10 @@ def union_with(self, other: "DimensionSet") -> "DimensionSet": added_dims = [dim for dim in other.dim_list if dim.letter not in self.letters] return self.expand_by(added_dims) - def difference_with(self, other: 'DimensionSet') -> 'DimensionSet': - difference_letters = [dim.letter for dim in self.dim_list if dim.letter not in other.letters] + def difference_with(self, other: "DimensionSet") -> "DimensionSet": + difference_letters = [ + dim.letter for dim in self.dim_list if dim.letter not in other.letters + ] return self.get_subset(difference_letters) @property diff --git a/sodym/named_dim_arrays.py b/sodym/named_dim_arrays.py index 24da81c..e4f6584 100644 --- a/sodym/named_dim_arrays.py +++ b/sodym/named_dim_arrays.py @@ -266,7 +266,9 @@ def split(self, dim_letter: str) -> dict: def get_shares_over(self, dim_letters: tuple) -> "NamedDimArray": """Get shares of the NamedDimArray along a tuple of dimensions, indicated by letter.""" - assert all([d in self.dims.letters for d in dim_letters]), 'Dimensions to get share of must be in the object' + assert all( + [d in self.dims.letters for d in dim_letters] + ), "Dimensions to get share of must be in the object" if all([d in dim_letters for d in self.dims.letters]): return self / self.sum_values() diff --git a/tests/test_named_dim_arrays.py b/tests/test_named_dim_arrays.py index 6332b0f..e7b1178 100644 --- a/tests/test_named_dim_arrays.py +++ b/tests/test_named_dim_arrays.py @@ -84,23 +84,23 @@ def test_sum_nda_to(): def test_get_shares_over(): # example of getting shares over one dimension - shares = space_animals.get_shares_over(dim_letters=('p')) + shares = space_animals.get_shares_over(dim_letters=("p")) assert shares.dims == space_animals.dims - wanted_values = np.einsum('pta,ta->pta', animal_values, 1/np.sum(animal_values, axis=0)) + wanted_values = np.einsum("pta,ta->pta", animal_values, 1 / np.sum(animal_values, axis=0)) assert_array_almost_equal(shares.values, wanted_values) # example of getting shares over two dimensions - shares = space_animals.get_shares_over(dim_letters=('p', 'a')) - wanted_values = np.einsum('pta,t->pta', animal_values, 1/np.sum(animal_values, axis=(0, 2))) + shares = space_animals.get_shares_over(dim_letters=("p", "a")) + wanted_values = np.einsum("pta,t->pta", animal_values, 1 / np.sum(animal_values, axis=(0, 2))) assert_array_almost_equal(shares.values, wanted_values) # example of getting shares over all dimensions - shares = space_animals.get_shares_over(dim_letters=('p', 't', 'a')) + shares = space_animals.get_shares_over(dim_letters=("p", "t", "a")) assert_array_almost_equal(shares.values, animal_values / np.sum(animal_values)) # example of getting shares over a dimension that doesn't exist with pytest.raises(AssertionError): - space_animals.get_shares_over(dim_letters=('s',)) + space_animals.get_shares_over(dim_letters=("s",)) def test_maths():