Repository: RemDelaporteMathurin/h-transport-materials

Issue:
PropertiesGroup.mean should have units
```python
import h_transport_materials as htm

print(htm.diffusivities.mean().units)
```

Prints

```
dimensionless
```

Discussion:

Patch:
diff --git a/h_transport_materials/properties_group.py b/h_transport_materials/properties_group.py
index ccc4b5f..1099a1b 100644
--- a/h_transport_materials/properties_group.py
+++ b/h_transport_materials/properties_group.py
@@ -92,9 +92,15 @@ class PropertiesGroup(list):
             default_range (tuple, optional): temperature range taken if
                 a Property doesn't have range. Defaults to (300, 1200).
 
+        Raises:
+            ValueError: When called on a mixed units group
+
         Returns:
             ArrheniusProperty: the mean arrhenius property
         """
+        if self.units == "mixed units":
+            raise ValueError("Can't compute mean on mixed units groups")
+
         # initialise data points
         data_T = np.array([])
         data_y = np.array([])
diff --git a/h_transport_materials/property.py b/h_transport_materials/property.py
index c2d7cee..b9994e2 100644
--- a/h_transport_materials/property.py
+++ b/h_transport_materials/property.py
@@ -184,6 +184,15 @@ class ArrheniusProperty(Property):
 
     @property
     def units(self):
+        # check if data_y is set
+        if hasattr(self, "data_y"):
+            if self.data_y is not None:
+                return self.data_y.units
+        # check if pre_exp is set
+        if hasattr(self, "pre_exp"):
+            return self.pre_exp.units
+
+        # return dimensionless by default
         return ureg.dimensionless
 
     @property


Test patch:
diff --git a/tests/test_properties_group.py b/tests/test_properties_group.py
index 31ab5cd..cd40a60 100644
--- a/tests/test_properties_group.py
+++ b/tests/test_properties_group.py
@@ -88,7 +88,7 @@ def test_mean(mean_D_0, mean_E_D):
     mean_prop = my_group.mean()
 
     # test
-    assert mean_prop.pre_exp == pytest.approx(mean_D_0, rel=0.2)
+    assert mean_prop.pre_exp.magnitude == pytest.approx(mean_D_0, rel=0.2)
     assert mean_prop.act_energy.magnitude == pytest.approx(mean_E_D, rel=0.2)
 
 
@@ -196,3 +196,20 @@ def test_units_property():
 
 def test_to_latex_table():
     htm.diffusivities.to_latex_table()
+
+
+def test_mean_has_units():
+    assert htm.diffusivities.mean().units == htm.ureg.m**2 * htm.ureg.s**-1
+
+
+def test_cannot_compute_mean_on_mixed_groups():
+    prop1 = htm.ArrheniusProperty(
+        0.1 * htm.ureg.dimensionless, 0.1 * htm.ureg.eV * htm.ureg.particle**-1
+    )
+    prop2 = htm.ArrheniusProperty(
+        0.1 * htm.ureg.m, 0.1 * htm.ureg.eV * htm.ureg.particle**-1
+    )
+    my_group = htm.PropertiesGroup([prop1, prop2])
+
+    with pytest.raises(ValueError, match="Can't compute mean on mixed units groups"):
+        my_group.mean()