Repository: PlasmaPy/PlasmaPy

Issue:
Document attribute `is_uniform` for AbstractGrid
@pheuer It appears that the `is_uniform` attribute on `AbstractGrid` is semi-public.  How do you feel about making this an actual property of the the class so it appears in the RTD documentation?


Discussion:
Sure, I'm looking into what this would entail right now.
How would you feel about having it be a cached property? It would be very time-intensive for it to be re-evaluated on every call (and right now it isn't).

Alternately, we could have a cached property `_is_uniform` and then a public property `is_uniform` that, when called, re-evaluates the private cached property.
Not sure if you have to go the whole route of a cached property.  I'd do something like...

```python
class AbstractGrid:
    def __init__(...):
        self._is_uniform = None
        if len(seeds) == 3:
            self._load_grids(...)

    def _load_grids(...):
       self._is_uniform = ...

    @property
    def is_uniform(self):
        if self._is_uniform is None:
            # handle how you like to
            ...
        return self._is_uniform
```

Or just give it a leading underscore and skip the property if you don't want it to be public.  It don't know what the overall usage is, so I'll leave the decision up to you.

Resolving patch:
diff --git a/plasmapy/plasma/grids.py b/plasmapy/plasma/grids.py
--- a/plasmapy/plasma/grids.py
+++ b/plasmapy/plasma/grids.py
@@ -49,6 +49,7 @@ def __init__(self, *seeds, num=100, **kwargs):
 
         # Initialize some variables
         self._interpolator = None
+        self._is_uniform = None
 
         # If three inputs are given, assume it's a user-provided grid
         if len(seeds) == 3:
@@ -241,6 +242,21 @@ def __getitem__(self, key):
         """
         return u.Quantity(self.ds[key].data, self.ds[key].attrs["unit"], copy=False)
 
+    @property
+    def is_uniform(self) -> bool:
+        """
+        A boolean value reflecting whether or not the grid points are
+        uniformly spaced.
+        """
+
+        if self._is_uniform is None:  # coverage: ignore
+            raise ValueError(
+                "The `is_uniform` attribute is not accessible "
+                "before a grid has been loaded."
+            )
+
+        return self._is_uniform
+
     @property
     def shape(self):
         r""" Shape of the grid"""
@@ -502,7 +518,7 @@ def _load_grid(
                 f"pts2 = {pts2.shape}."
             )
 
-        self.is_uniform = _detect_is_uniform_grid(pts0, pts1, pts2)
+        self._is_uniform = _detect_is_uniform_grid(pts0, pts1, pts2)
 
         # Create dataset
         self.ds = xr.Dataset()


Test patch:
diff --git a/plasmapy/plasma/tests/test_grids.py b/plasmapy/plasma/tests/test_grids.py
--- a/plasmapy/plasma/tests/test_grids.py
+++ b/plasmapy/plasma/tests/test_grids.py
@@ -86,13 +86,17 @@ def test_AbstractGrid():
     with pytest.raises(KeyError):
         grid.require_quantities(req_q, replace_with_zeros=False)
     # Do replace
-    grid.require_quantities(req_q, replace_with_zeros=True)
+    with pytest.warns(RuntimeWarning, match="This quantity will be assumed to be zero"):
+        grid.require_quantities(req_q, replace_with_zeros=True)
     req_q = ["B_x", "B_y"]
     # Test with a key that is not there, but cannot be replaced because
     # it's not a recognized key
     req_q = ["B_x", "not_a_recognized_key"]
     with pytest.raises(KeyError):
-        grid.require_quantities(req_q, replace_with_zeros=True)
+        with pytest.warns(
+            RuntimeWarning, match="This quantity will be assumed to be zero"
+        ):
+            grid.require_quantities(req_q, replace_with_zeros=True)
 
     # Test adding a quantity with wrong units
     q = np.random.randn(10, 10, 10) * u.kg