Skip to content

Saving TDB with A*(B+C) expressions#522

Merged
richardotis merged 7 commits into
pycalphad:developfrom
nury12n:nested_mul_add
Mar 26, 2024
Merged

Saving TDB with A*(B+C) expressions#522
richardotis merged 7 commits into
pycalphad:developfrom
nury12n:nested_mul_add

Conversation

@nury12n

@nury12n nury12n commented Mar 26, 2024

Copy link
Copy Markdown
Collaborator

This is a minor fix to an issue I was having when saving a Database to a TDB file.

If the TDB had a parameter with the expression A*(B+C) it would get saved as A*B+C, removing the parenthesis around the Add expression.

Changes

  • When stringify-ing expressions through TCPrinter and the expression is a Mul object, this checks if the arguments in Mul is an Add object and explicitly adds parenthesis if it is.
  • Refactoring the elif block that processes the Mul object, since all arguments in the Mul object can be treated the same and joined together.
  • Tests for ensuring that parenthesis around Add expressions are retained and that parentheses are not unnecessarily added when the argument in Mul is not Add.

@codecov

codecov Bot commented Mar 26, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.48%. Comparing base (716d923) to head (650e85e).
Report is 4 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #522      +/-   ##
===========================================
+ Coverage    90.46%   90.48%   +0.01%     
===========================================
  Files           50       50              
  Lines         7868     7880      +12     
===========================================
+ Hits          7118     7130      +12     
  Misses         750      750              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@richardotis richardotis merged commit 2953e0a into pycalphad:develop Mar 26, 2024
ricardonpa added a commit to ricardonpa/pycalphad that referenced this pull request Jun 24, 2024
richardotis pushed a commit that referenced this pull request Jun 24, 2024
…516)

* Fix float exponents when writing a TDB file (TC ERROR DatabaseUtils)

* Update previous exponent float fix + Fix line breaks causing TC reading function ERROR

* Generalized the line-break rules to accept a break before any number addition/subtraction that is not part of an EXP or LN/LOG operation. Updated the test in test_database.py to reflect changes made in tdb.py.

* Update #522 expressions and by removing extra spaces to resolve conflicts

* Add comment to clarify usage of regex expression.

* Update tdb.py to account for errors when trying to use int() on exponents with nested functions, i.e., non-numeric values.

* Updated `test_tc_printer_exp` to test if exponents are being written as integers

* Create `test_reflow_text_for_line_breaks` function to test if lines are being broken at correct positions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants