ihmeuw-msca / pyDisagg

BSD 2-Clause "Simplified" License
1 stars 0 forks source link

Use getter and setter rather than pull_set_rate_pattern #22

Closed AHsu98 closed 1 year ago

AHsu98 commented 1 year ago
          Hi @AHsu98! I think the function `pull_set_rate_pattern` is a little confusing. Usually the setter and getter are separate. I recommend using `property` to create a setter and getter for `rate_pattern`:
class DisaggModel:
    def __init__(self, ..., rate_pattern: Optional[NDArray] = None, ...):
        self._rate_pattern = rate_pattern

    @property
    def rate_pattern(self) -> NDArray:
        if self._rate_pattern is None:
            raise ValueError("No Rate Pattern Available")
        return self._rate_pattern

    @rate_pattern.setter
    def rate_pattern(self, rate_pattern: Optional[NDArray]):
        if rate_pattern is not None:
            self._rate_pattern = rate_pattern

    def fit_beta(self, ...):
        self.rate_pattern = rate_pattern

For more detail on setter and getter, please check https://realpython.com/python-getter-setter/#using-properties-instead-of-getters-and-setters-the-python-way

_Originally posted by @zhengp0 in https://github.com/ihmeuw-msca/pyDisagg/pull/20#discussion_r1113639606_