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 8 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.

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