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

113 add markdown to descriptions #118

Merged
merged 10 commits into from
Mar 29, 2024

Conversation

jcadam14
Copy link
Contributor

Closes #113

Note, currently the pytest is pointing to the raw csv on the branch for cfpb/sbl-content#21. Once those changes are merged in, the pytest can be pointed back to main. So the approval of this PR can wait until that other issue is merged and then I'll reupdate the pytests for final approval.

@jcadam14 jcadam14 linked an issue Mar 25, 2024 that may be closed by this pull request
Copy link

github-actions bot commented Mar 25, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/regtech_data_validator
  checks.py
  phase_validations.py
Project Total  

This report was generated by python-coverage-comment-action

Comment on lines 638 to 646
"When 'action taken' equals 3 (denied), 4 (withdrawn by applicant), or 5 (incomplete), the following fields must all equal 999 (not applicable):\n"
"* 'Interest rate type'\n"
"* 'MCA/sales-based: additional cost for merchant cash advances or other sales-based financing: NA flag'\n"
"* 'Prepayment penalty could be imposed'\n"
"* 'Prepayment penalty exists'\n\n"
"And the following fields must all be blank:\n\n"
"* 'Total origination charges'\n"
"* 'Amount of total broker fees'\n"
"* 'Initial annual charges'"
Copy link
Member

@hkeeler hkeeler Mar 26, 2024

Choose a reason for hiding this comment

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

For these long ones, or maybe just any that aren't one-liners, it might be cleaner to use Python's multiline string, with textwrap.dedent. You'd end up with something like:

from textwrap import dedent

...

                    description="""\    
                        When 'action taken' equals 3 (denied), 4 (withdrawn by applicant), or 5 (incomplete), the following fields must all equal 999 (not applicable):

                        * 'Interest rate type'
                        * 'MCA/sales-based: additional cost for merchant cash advances or other sales-based financing: NA flag'
                        * 'Prepayment penalty could be imposed'
                        * 'Prepayment penalty exists'
                        
                        And the following fields must all be blank:

                        * 'Total origination charges'
                        * 'Amount of total broker fees'
                        * 'Initial annual charges'
                        ```.dedent()

With this model, you can pretty much copy/paste the markdown and not have to worry about all the quotes and \n and that fun.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah cool was not familiar with dedent. Just read the api and yeah that would make this code prettier. I'll give that a go. Will possibly need to redo the csv depending on how it spits out stuff but it should match.

src/regtech_data_validator/checks.py Show resolved Hide resolved
@jcadam14 jcadam14 requested a review from hkeeler March 26, 2024 23:04
Copy link
Member

@hkeeler hkeeler left a comment

Choose a reason for hiding this comment

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

@jcadam14, how are you feeling about all this? Having the multiline strings seems like a bit of an improvement, but it does look a little odd still, and it seems like it's had implications for the CSV file (cfpb/sbl-content#22 (review)). Do you think we should keep it, or revert back to what you had before?

Looks like there are still quite a few descriptions in the old form. If we decide to keep the multiline, we should probably make 'em all like that.

Comment on lines 187 to 191
description=dedent(
"""\
* When 'credit product' does **not** equal 977 (other), 'free-form text field for other credit products' must be blank.
* When 'credit product' equals 977, 'free-form text field for other credit products' must **not** be blank.
"""
Copy link
Member

Choose a reason for hiding this comment

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

Did black format it this way, with the offset """s?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup

Comment on lines 507 to 509
"* 'Credit purpose' and 'free-form text field for other credit "
"purpose' combined should **not** contain more than three values. "
"Code 977 (other), within 'credit purpose', does **not** count "
Copy link
Member

Choose a reason for hiding this comment

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

This one is still the non-dedent flavor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only used dedent on descriptions with actual multiple lines, the \n's. This is a single line description, but split into multiple strings for readability.

Comment on lines 938 to 939
* When 'interest rate type' does **not** equal 3 (initial rate period > 12 months, adjustable interest), \
4 (initial rate period > 12 months, fixed interest), 5 (initial rate period <= 12 months, adjustable interest), \
Copy link
Member

Choose a reason for hiding this comment

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

It should be valid Markdown without the trailing \. Is that needed to keep in sync with the CSV?

Copy link
Contributor Author

@jcadam14 jcadam14 Mar 27, 2024

Choose a reason for hiding this comment

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

The \ are there to break the string up in the python file so you don't get a single line that looks like "* When 'interest rate type' does not equal 3 (initial rate period > 12 months, adjustable interest), 4 (initial rate period > 12 months, fixed interest), 5 (initial rate period <= 12 months, adjustable interest)..." and runs off the page in the IDE.

Which technically should break our linting but black has issues with long string reformatting.

@jcadam14
Copy link
Contributor Author

@jcadam14, how are you feeling about all this? Having the multiline strings seems like a bit of an improvement, but it does look a little odd still, and it seems like it's had implications for the CSV file (cfpb/sbl-content#22 (review)). Do you think we should keep it, or revert back to what you had before?

Looks like there are still quite a few descriptions in the old form. If we decide to keep the multiline, we should probably make 'em all like that.

Most descriptions are actually one single line/string, but they're broken up in the python file for readability. Need to make a distinction there. The ones that are actually multiline descriptions have been dedented.

Honestly, the python looks cleaner, but the output to the csv and markdown (before being rendered) is uglier. Depends on if someone using the csv at some point wants a bunch of \n's.

@jcadam14 jcadam14 requested a review from hkeeler March 27, 2024 02:05
Copy link
Member

@hkeeler hkeeler left a comment

Choose a reason for hiding this comment

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

Looking good. Found a little clump with leftover "s. Founds similar artifacts over in PR cfpb/sbl-content#22 too. I think just the one little fixup and we're good. Thanks for slogging through all this.

src/regtech_data_validator/phase_validations.py Outdated Show resolved Hide resolved
src/regtech_data_validator/phase_validations.py Outdated Show resolved Hide resolved
src/regtech_data_validator/phase_validations.py Outdated Show resolved Hide resolved
@@ -36,7 +13,7 @@ def test_csv_differences(self):
]

csv_df = pd.read_csv(
"https://raw.githubusercontent.com/cfpb/sbl-content/main/fig-files/validation-spec/2024-validations.csv"
"https://raw.githubusercontent.com/cfpb/sbl-content/21-update-descriptions-for-markdown/fig-files/validation-spec/2024-validations.csv"
Copy link
Member

Choose a reason for hiding this comment

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

Assuming we'll merge PR cfpb/sbl-content#22 first.

Suggested change
"https://raw.githubusercontent.com/cfpb/sbl-content/21-update-descriptions-for-markdown/fig-files/validation-spec/2024-validations.csv"
"https://raw.githubusercontent.com/cfpb/sbl-content/main/fig-files/validation-spec/2024-validations.csv"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch thank you. After I updated I went through each to check for just this but your eyes start to cross after awhile!

Copy link
Member

Choose a reason for hiding this comment

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

Yep. No doubt. 😄

@jcadam14 jcadam14 requested a review from hkeeler March 28, 2024 14:49
@hkeeler hkeeler merged commit 30bd513 into main Mar 29, 2024
5 checks passed
@hkeeler hkeeler deleted the 113-add-markdown-to-errorwarning-descriptions branch March 29, 2024 04:06
jcadam14 added a commit that referenced this pull request May 3, 2024
Closes #113 

- Updated phase_validations to include markdown based on wagtail
descriptions
https://www.consumerfinance.gov/data-research/small-business-lending/filing-instructions-guide/2024-guide/#4
- Updated pytest to be much simpler as it now just needs to do a direct
description comparison instead of reformatting due to csv formatting.
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.

Add markdown to error/warning descriptions
2 participants