Skip to content
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

Fixup mypy errors in sampling.py #4327

Merged
merged 2 commits into from
Dec 13, 2020

Conversation

MarcoGorelli
Copy link
Contributor

I understand there's some disagreement about the usefulness of type hints, so perhaps we don't need to type everything, but I think that at least the types hints that are already there shouldn't throw errors

Comment on lines 1922 to 1931
vars_ = [var.name for var in prior_vars + prior_pred_vars]
vars = set(vars_)
vars_: Iterable[str] = [var.name for var in prior_vars + prior_pred_vars]
elif vars is None:
vars = var_names
vars_ = vars
elif vars is not None:
assert var_names is not None # help mypy
vars_ = var_names
elif var_names is None:
warnings.warn("vars argument is deprecated in favor of var_names.", DeprecationWarning)
vars_ = vars
else:
raise ValueError("Cannot supply both vars and var_names arguments.")
vars = cast(TIterable[str], vars) # tell mypy that vars cannot be None here.
Copy link
Contributor Author

@MarcoGorelli MarcoGorelli Dec 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only vars_ is used after this point, any reason to assign to vars?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reason is in the first if branch: vars = set(vars_). Looks like the for in Line 1945/1956 is supposed to iterate over each value exactly once.

pymc3/step_methods/arraystep.py Show resolved Hide resolved
pymc3/step_methods/mlda.py Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Dec 12, 2020

Codecov Report

Merging #4327 (66f4ed6) into master (6f15cbb) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4327      +/-   ##
==========================================
+ Coverage   87.66%   87.68%   +0.02%     
==========================================
  Files          88       88              
  Lines       14264    14240      -24     
==========================================
- Hits        12504    12486      -18     
+ Misses       1760     1754       -6     
Impacted Files Coverage Δ
pymc3/step_methods/mlda.py 95.50% <ø> (-0.02%) ⬇️
pymc3/sampling.py 89.69% <100.00%> (+0.03%) ⬆️
pymc3/step_methods/arraystep.py 92.61% <100.00%> (+0.15%) ⬆️
pymc3/model.py 88.90% <0.00%> (+0.02%) ⬆️
pymc3/distributions/distribution.py 95.28% <0.00%> (+0.24%) ⬆️
pymc3/theanof.py 90.47% <0.00%> (+0.86%) ⬆️

CategoricalGibbsMetropolis,
PGBART,
CompoundStep,
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users may implement their own step method. All of these should already inherit from arraystep.BlockedStep.

pymc3/sampling.py Show resolved Hide resolved
elif vars is not None:
assert var_names is not None # help mypy
vars_ = var_names
elif var_names is None:
warnings.warn("vars argument is deprecated in favor of var_names.", DeprecationWarning)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For how long has this been in? 4.0 is coming up, so we might as well remove that kwarg already. Would make some of this typing easier too.

pymc3/sampling.py Show resolved Hide resolved
Comment on lines 1922 to 1931
vars_ = [var.name for var in prior_vars + prior_pred_vars]
vars = set(vars_)
vars_: Iterable[str] = [var.name for var in prior_vars + prior_pred_vars]
elif vars is None:
vars = var_names
vars_ = vars
elif vars is not None:
assert var_names is not None # help mypy
vars_ = var_names
elif var_names is None:
warnings.warn("vars argument is deprecated in favor of var_names.", DeprecationWarning)
vars_ = vars
else:
raise ValueError("Cannot supply both vars and var_names arguments.")
vars = cast(TIterable[str], vars) # tell mypy that vars cannot be None here.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reason is in the first if branch: vars = set(vars_). Looks like the for in Line 1945/1956 is supposed to iterate over each value exactly once.

@twiecki twiecki merged commit b386d94 into pymc-devs:master Dec 13, 2020
@twiecki
Copy link
Member

twiecki commented Dec 13, 2020

Thanks @MarcoGorelli!

@MarcoGorelli MarcoGorelli deleted the sort-out-typing branch December 13, 2020 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants