Repository: econ-ark/HARK

Issue:
Cannot make a DiscreteDistributionLabeled from a Bernoulli variable
```
foo = Bernoulli(.4)
DiscreteDistributionLabeled.from_unlabeled(
               foo,
               var_names = ['foo']
            )
```

```
File ~/projects/HARK/HARK/distribution.py:1087, in DiscreteDistributionLabeled.from_unlabeled(cls, dist, name, attrs, var_names, var_attrs)
   1077 @classmethod
   1078 def from_unlabeled(
   1079     cls,
   (...)
   1084     var_attrs=None,
   1085 ):
   1086     ldd = cls(
-> 1087         dist.pmv,
   1088         dist.atoms,
   1089         seed=dist.seed,
   1090         limit=dist.limit,
   1091         name=name,
   1092         attrs=attrs,
   1093         var_names=var_names,
   1094         var_attrs=var_attrs,
   1095     )
   1097     return ldd

AttributeError: 'Bernoulli' object has no attribute 'pmv'
```

Discussion:

Patch:
diff --git a/HARK/distribution.py b/HARK/distribution.py
index 40c88c93..d26ecec8 100644
--- a/HARK/distribution.py
+++ b/HARK/distribution.py
@@ -769,6 +769,10 @@ class Bernoulli(DiscreteFrozenDistribution):
         # Set up the RNG
         super().__init__(stats.bernoulli, p=self.p, seed=seed)
 
+        self.pmv = [1 - self.p, self.p]
+        self.atoms = [0, 1]
+        self.limit = {"dist": self}
+
 
 class DiscreteDistribution(Distribution):
     """


Test patch:
diff --git a/HARK/tests/test_distribution.py b/HARK/tests/test_distribution.py
index c9f292f3..cc1c5b58 100644
--- a/HARK/tests/test_distribution.py
+++ b/HARK/tests/test_distribution.py
@@ -607,6 +607,12 @@ class DiscreteDistributionLabeledTests(unittest.TestCase):
             )
         )
 
+    def test_Bernoulli_to_labeled(self):
+        p = 0.4
+        foo = Bernoulli(p)
+        bern = DiscreteDistributionLabeled.from_unlabeled(foo, var_names=["foo"])
+        self.assertTrue(np.allclose(bern.expected(), p))
+
 
 class labeled_transition_tests(unittest.TestCase):
     def setUp(self) -> None: