Skip to content

Replace VarName with built-in str #7855

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

osyuksel
Copy link
Contributor

@osyuksel osyuksel commented Jul 17, 2025

Description

This change:

  • Replaces VarName type with built-in str
  • Updates get_var_name to have it work without getattr

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pymc--7855.org.readthedocs.build/en/7855/

@osyuksel
Copy link
Contributor Author

osyuksel commented Jul 17, 2025

I also attempted to address the second point re. getattr(variable, "name") in the issue with this commit, however, making an explicit attribute reference (i.e. calling var.name instead of getattr) causes the tests to fail, so I assume there must be some variables where the attribute is not present.

==================================== ERRORS ====================================
__________________ ERROR collecting tests/test_model_graph.py __________________
tests/test_model_graph.py:467: in <module>
    class TestVariableSelection:
tests/test_model_graph.py:499: in TestVariableSelection
    ModelGraph(model_with_different_descendants()).vars_to_plot(),
pymc/model_graph.py:238: in __init__
    self._all_var_names = get_default_varnames(self.model.named_vars, include_transformed=False)
pymc/util.py:212: in get_default_varnames
    return [var for var in var_iterator if not is_transformed_name(get_var_name(var))]
pymc/util.py:217: in get_var_name
    return str(var.name if var.name is not None else var)
E   AttributeError: 'str' object has no attribute 'name'

@osyuksel osyuksel changed the title Remove VarName for codebase Replace VarName with built-in str Jul 17, 2025
@osyuksel osyuksel marked this pull request as ready for review July 17, 2025 12:07
@ricardoV94
Copy link
Member

That should check explicitly if the input is a string, instead of trying to call var.name on it

osyuksel added 2 commits July 17, 2025 17:57
if var.name is None, current get_var_name returns "None", not str(var)
@osyuksel
Copy link
Contributor Author

Makes sense, missed that var could be str. Updated PR.

Copy link

codecov bot commented Jul 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.65%. Comparing base (dc7cfee) to head (afcc142).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7855      +/-   ##
==========================================
+ Coverage   88.25%   91.65%   +3.40%     
==========================================
  Files         116      116              
  Lines       18845    18844       -1     
==========================================
+ Hits        16631    17272     +641     
+ Misses       2214     1572     -642     
Files with missing lines Coverage Δ
pymc/model/core.py 93.38% <100.00%> (ø)
pymc/model_graph.py 84.48% <100.00%> (ø)
pymc/util.py 81.11% <100.00%> (-0.09%) ⬇️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Remove VarName from codebase
2 participants