Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Error when printing estimated proportions with no domains #59

@michaelwalshe

Description

@michaelwalshe

Hi,

I've encountered the following error when printing a proportion estimator:

from samplics import TaylorEstimator
from samplics.datasets import load_nhanes2
from samplics.utils.types import PopParam

nhanes2 = load_nhanes2()["data"]

prop_est = TaylorEstimator(PopParam.prop)

prop_est.estimate(
    y=nhanes2["highlead"],
    psu=nhanes2["psuid"],
    stratum=nhanes2["stratid"],
    remove_nan=True,
)

print(prop_est)

Gives the following:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File c:\\Users\\Michael.Walshe.AMADEUS\\source\\katalyze-data\\CAMIS\\testing.py:1
----> 1 print(prop_est)

File c:\\Users\\Michael.Walshe.AMADEUS\\source\\katalyze-data\\CAMIS\\renv\\python\\virtualenvs\\renv-python-3.11\\Lib\\site-packages\\samplics\\estimation\\expansion.py:109, in _SurveyEstimator.__str__(self)
    107 upper_ci = list()
    108 coef_var = list()
--> 109 for domain in self.domains:
    110     domains += np.repeat(domain, len(self.point_est[domain])).tolist()
    111     levels += list(self.point_est[domain].keys())

TypeError: iteration over a 0-d array

I think this is due to the __str__ method of SurveyEstimator checking that self.domain is not None rather than self.domain.shape in ((), (0,)) which is what it looks like the checks are elsewhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions