Skip to content

Fix incorrect warnings and exception types in model.py and datacollection.py#3434

Merged
quaquel merged 7 commits intomesa:mainfrom
codebyNJ:fix/model-datacollection-warnings
Mar 10, 2026
Merged

Fix incorrect warnings and exception types in model.py and datacollection.py#3434
quaquel merged 7 commits intomesa:mainfrom
codebyNJ:fix/model-datacollection-warnings

Conversation

@codebyNJ
Copy link
Copy Markdown
Contributor

@codebyNJ codebyNJ commented Mar 4, 2026

Summary

  • Remove duplicate self.time: float = 0.0 assignment in Model.__init__
  • Fix inverted warning messages in Model._advance_time() and Model.run_until() — the condition checks until <= self.time but the message said "is larger than" (should say "is not larger than")
  • Fix DataCollector.get_model_vars_dataframe() and get_agent_vars_dataframe() — they used raise UserWarning(...) which crashes the caller instead of issuing a warning. Changed to warnings.warn() with a graceful return pd.DataFrame()
  • Replace bare raise Exception(...) with raise ValueError(...) in add_table_row() and get_table_dataframe() for better exception specificity

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2026

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -0.6% [-1.1%, +0.0%] 🔵 -0.1% [-0.8%, +0.7%]
BoltzmannWealth large 🔵 -1.8% [-3.1%, -0.4%] 🟢 -10.1% [-12.8%, -7.5%]
Schelling small 🔵 -3.4% [-4.0%, -2.8%] 🔵 -0.6% [-1.2%, -0.1%]
Schelling large 🔵 -3.2% [-5.0%, -1.6%] 🟢 -13.9% [-17.1%, -11.2%]
WolfSheep small 🔵 -2.9% [-4.0%, -1.7%] 🔵 -0.4% [-1.8%, +0.9%]
WolfSheep large 🟢 -5.7% [-7.4%, -3.9%] 🟢 -9.0% [-12.0%, -5.7%]
SugarscapeG1mt small 🟢 -4.8% [-5.4%, -4.1%] 🔵 -2.2% [-3.2%, -1.2%]
SugarscapeG1mt large 🔵 -2.5% [-3.8%, -1.1%] 🔵 -2.7% [-3.7%, -1.9%]
BoidFlockers small 🔵 -0.5% [-1.1%, +0.2%] 🔵 -0.6% [-1.1%, -0.1%]
BoidFlockers large 🔵 -0.4% [-1.9%, +0.8%] 🔵 -0.1% [-1.0%, +1.0%]

"""
if table_name not in self.tables:
raise Exception("Table does not exist.")
raise ValueError(f"Table '{table_name}' does not exist.")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am wondering whether we should not use a custom exception here instead?

Copy link
Copy Markdown
Member

@quaquel quaquel left a comment

Choose a reason for hiding this comment

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

One suggestion, but looks fine otherwise.

@codebyNJ
Copy link
Copy Markdown
Contributor Author

codebyNJ commented Mar 5, 2026

One suggestion, but looks fine otherwise.

I have updated the PR with custom exceptions.

Copy link
Copy Markdown
Member

@quaquel quaquel left a comment

Choose a reason for hiding this comment

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

One last suggestion.

@quaquel quaquel merged commit deaef60 into mesa:main Mar 10, 2026
14 checks passed
@EwoutH EwoutH added the bug Release notes label label Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants