Repository: pymc-devs/pymc
Pull request: Refactor get_tau_sigma to handle lists
Non-`Variable` arguments converted to arrays before bounds checking. Added simple test.

Closes #5745 

Problem statement:
TypeError when passing list of values as sigma
`get_tau_sigma` used in many of our distributions fails with a `TypeError` when passing a list of values. We should probably fix this for better user experience:

```python
import pymc as pm:
pm.Normal.dist(sigma=[1, 2])
```
```
TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'float'
```

Hints from issue discussion:

Commit message: Black formatted

Patch to review:
diff --git a/pymc/distributions/continuous.py b/pymc/distributions/continuous.py
index 40d4c1a3ac..1f8a93c396 100644
--- a/pymc/distributions/continuous.py
+++ b/pymc/distributions/continuous.py
@@ -226,8 +226,8 @@ def get_tau_sigma(tau=None, sigma=None):
             if isinstance(sigma, Variable):
                 sigma_ = check_parameters(sigma, sigma > 0, msg="sigma > 0")
             else:
-                assert np.all(np.asarray(sigma) > 0)
-                sigma_ = sigma
+                sigma_ = np.asarray(sigma)
+                assert np.all(sigma_ > 0), "sigma must be positive"
             tau = sigma_**-2.0
 
     else:
@@ -237,9 +237,8 @@ def get_tau_sigma(tau=None, sigma=None):
             if isinstance(tau, Variable):
                 tau_ = check_parameters(tau, tau > 0, msg="tau > 0")
             else:
-                assert np.all(np.asarray(tau) > 0)
-                tau_ = tau
-
+                tau_ = np.asarray(tau)
+                assert np.all(tau_ > 0), "tau must be positive"
             sigma = tau_**-0.5
 
     return floatX(tau), floatX(sigma)
diff --git a/pymc/tests/test_distributions.py b/pymc/tests/test_distributions.py
index cb485a086f..536e337457 100644
--- a/pymc/tests/test_distributions.py
+++ b/pymc/tests/test_distributions.py
@@ -2413,6 +2413,11 @@ def test_get_tau_sigma(self):
         with pytest.raises(ParameterValueError):
             sigma.eval()
 
+        sigma = [1, 2]
+        assert_almost_equal(
+            get_tau_sigma(sigma=sigma), [1.0 / np.array(sigma) ** 2, np.array(sigma)]
+        )
+
     @pytest.mark.parametrize(
         "value,mu,sigma,nu,logp",
         [


Code review comments:
diff_hunk: @@ -237,9 +237,8 @@ def get_tau_sigma(tau=None, sigma=None):
             if isinstance(tau, Variable):
                 tau_ = check_parameters(tau, tau > 0, msg="tau > 0")
             else:
-                assert np.all(np.asarray(tau) > 0)
-                tau_ = tau
-
+                tau_ = np.asarray(tau)
+                assert np.all(tau_ > 0), "tau must be positive"
path: pymc/distributions/continuous.py
text: @user1:
While we are here, we should replace the asserts by a ValueError