-
-
Notifications
You must be signed in to change notification settings - Fork 429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to type hint with InferenceData #2415
Comments
What I've done in the past is |
Thanks @tomicapretto for the suggestion. I agree this is the "best" method when using ArviZ and what looks to me is pyright in neovim @wd60622. The reason why one would get these type errors is because the arviz/arviz/data/inference_data.py Line 94 in 0fc1117
Allowing you to use "dot" notation is built into the InferenceData object, which is why you can use it, but it will give you the type errors you see. To remove those errors, I would also suggest doing the following. def function(idata: az.InferenceData) -> None:
idata["prior"]
idata["posterior"]
idata["posterior_predictive"]
idata["sample_stats"]
idata["log_likelihood"] Then you will not get the type errors you see, since you are accessing the |
I personally dont use brackets. Seems imprecise. Does this warn with idata["unlikely_key"]? |
No, but neither would a dictionary, which is what the InferenceData object is based on. This is a deep issue with how Python objects are created, and I do not see an immediate answer. I have seen this type confusion before with InferenceData objects and other users, so you are in good company. Let me think about it more, since there are ways to allow for this notation in Python. Take for example the following where I've converted the InferenceData object to a |
How can I avoid this?
Aren't the groups "defined" or restricted to a small set?
Might be related to #1581 but I interpreted that as internal type hinting
The text was updated successfully, but these errors were encountered: