Skip to content

fix: Fix the hierarchy associated with ProfileParser.parse_file() and PDFParser.parse_file() - #192

Open
cadenmyers13 wants to merge 10 commits into
diffpy:v3.3.0from
cadenmyers13:fix-bugs-v330
Open

fix: Fix the hierarchy associated with ProfileParser.parse_file() and PDFParser.parse_file()#192
cadenmyers13 wants to merge 10 commits into
diffpy:v3.3.0from
cadenmyers13:fix-bugs-v330

Conversation

@cadenmyers13

Copy link
Copy Markdown
Contributor

A few bugs were caught here by claude.

  1. PDFContribution.loadData() was discarding PDF-specific metadata because it didn't use PDFParser to parse data. This class isnt used much in practice but good to fix.
  2. ProfileParser.parse_file() parses metadata file like a string rather than by line. Now it checks whether a subclass (like PDFParser) overrides this behavior before parsing. This was behavior I changed earlier which I reverted back to because it makes ProfileParser more extensible.
  3. I missed a pushFitHooks to push_fit_hooks, so that is changed.

Also some docs changes. All of this is backwards compatible with the deprecated functions. More tests have been added. ProfileParser did not have many tests to begin with.

@cadenmyers13

Copy link
Copy Markdown
Contributor Author

@sbillinge ready for review

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.56098% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.44%. Comparing base (0b16bfd) to head (0965c01).
⚠️ Report is 4 commits behind head on v3.3.0.

Files with missing lines Patch % Lines
tests/test_profileparser.py 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           v3.3.0     #192      +/-   ##
==========================================
+ Coverage   79.08%   81.44%   +2.35%     
==========================================
  Files          25       25              
  Lines        3821     3837      +16     
==========================================
+ Hits         3022     3125     +103     
+ Misses        799      712      -87     
Files with missing lines Coverage Δ
tests/test_pdf.py 60.49% <100.00%> (+8.31%) ⬆️
tests/test_profileparser.py 97.67% <93.75%> (-2.33%) ⬇️

... and 2 files with indirect coverage changes

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

@sbillinge sbillinge left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please see comments


self.select_bank(0)
return
If a subclass overrides `parse_string`, e.g.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

when you say overrides do you mean overloads? Or is overrides a recognized term of art? I am not sure is why I am asking (and I guess Claude may have been involved and Claude generally uses the right terminology). I suggest to check this and then correct it everywhere if it needs it, or not if not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@sbillinge Overriding is when a subclass redefines a method it inherits, so override is correct in this case. "Override" is not used anywhere else so we should be good on updating

The path to the data file.
"""
parser = ProfileParser()
parser = PDFParser()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please check this change is correct. Didn't we move from PDFParser to ProfileParser because the parser is more general than PDF? For example, couldn't it parse I(Q) data or anything else?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@sbillinge We did and this changes it back. I changed it back because it seems like the intended design of ProfileParser was to be an inherited class for any parser in the future. For example, PDFParser inherits ProfileParser which contains the templating for a parser object. So this could be extended to other parsers, say, an IQParser. Each parser can be designed for a specific file format. In this case, PDFParser is for pdfgetx3 .gr files. It still uses load_data from diffpy.utils though which is and improvement from what it was before

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

right, but getx3 files include iq files and sq and fq files which don't have PDF data in but could be read with the same parser. Also, I think .chi files coming from pyfai so it is not even a getx3 standard. How about maybe calling it GetxParser or something like that?

Comment thread tests/test_pdf.py
# reads generic column data instead. These tests pin that boundary.


def test_parse_file_extracts_pdf_metadata(datafile):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a reason these tests are not using pytest.mark.parametrize and the group standards for annotating the different cases?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@sbillinge This is testing that the metadata is actually extracted from an example data file. I didn't think more cases were needed. In tests with only one case do we still want to use parameterize?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did parameterize the deprecated function though

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I saw that, but was seeing a whole series of tests, each testing one thing, so I thought it could be paramaterized.

Comment thread tests/test_profileparser.py Outdated


def test_parse_file_bad_parser(
parser_datafiles,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

again here, we seem to have lost our paramatrize pattern. It makes it harder to follow

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@sbillinge touche, will make those changes

@cadenmyers13

Copy link
Copy Markdown
Contributor Author

@sbillinge ready for review

@sbillinge sbillinge left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That looks better, thanks. Please see my comment about the naming though.

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