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

allow merge_section to merge children classes #143

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

aalbino2
Copy link
Contributor

@aalbino2 aalbino2 commented Dec 2, 2024

That's it.

Instead of going for the m_section_def, one can go for the name of the property, that remains always the same when some child class is used.

What do you think?

Summary by Sourcery

Enhancements:

  • Modify merge_sections function to use property names instead of sub_section_def for merging child classes.

@aalbino2 aalbino2 linked an issue Dec 2, 2024 that may be closed by this pull request
Copy link

sourcery-ai bot commented Dec 2, 2024

Reviewer's Guide by Sourcery

The PR modifies the merge_sections function to use section names instead of section definitions when handling sub-sections, making it more flexible for child classes. The change replaces direct section definition references with name-based lookups in all sub-section operations.

Class diagram for merge_sections function update

classDiagram
    class Section {
        +m_sub_section_count(name)
        +m_get_sub_section(name, index)
        +m_add_sub_section(name, sub_section)
    }
    class Update {
        +m_def: Definition
        +m_get_sub_sections(name)
        +m_sub_section_count(name)
    }
    class Definition {
        +all_sub_sections: Map
    }
    Section --> Definition
    Update --> Definition
    note for Section "Updated to use name instead of sub_section_def"
    note for Update "Updated to use name instead of sub_section_def"
Loading

File-Level Changes

Change Details Files
Refactored sub-section handling to use name-based lookups instead of section definitions
  • Changed sub-section iteration to use only the name from all_sub_sections, discarding the section definition
  • Updated sub-section count checks to use name-based lookups
  • Modified sub-section addition to use name parameter instead of section definition
  • Updated recursive merge calls to use name-based section retrieval
src/nomad_measurements/utils.py

Possibly linked issues

  • Add XRD Plugin #1: The PR implements changes to allow merge_section to merge child classes, addressing the issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @aalbino2 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Please provide a more detailed description of the problem you're trying to solve. What issues were you encountering with child classes that required this change?
  • Consider adding test cases that demonstrate both the problem with the current implementation and how your changes fix it
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@hampusnasstrom
Copy link
Collaborator

I guess as long as it works it should be good. Can you add a test case to the unit test which breaks with the old implementation and is fixed with the new one?

@hampusnasstrom
Copy link
Collaborator

Ah, I see now that the old tests don't run. I guess the first step would be to get those to run.

Copy link
Collaborator

@ka-sarthak ka-sarthak left a comment

Choose a reason for hiding this comment

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

Nice idea! However, the if clause will need to be more involved. The current way of implementing might not work as section.m_def.all_base_sections points to a list of parent sections and does not contain the current section. I have added a suggestion to fix this.

But there's another issue. Most of the sections that will be used in merge_sections will always have common inherited sections like BaseSection or ArchiveSection. So the if will always be True even when we don't want it to be.

Or do you intend to do something else than what I understood?

@aalbino2
Copy link
Contributor Author

aalbino2 commented Dec 3, 2024

Thanks for the fix, it looks better. For the truth of the statement I intend that update.m_def will always be a parent of section.m_def, not the opposite. So if update is not a parent of section, the statement will be false.

Ah wait, in your suggestion this is a not missing, oder ? @ka-sarthak

@ka-sarthak
Copy link
Collaborator

Ah, not should be added for sure

@ka-sarthak
Copy link
Collaborator

Okay, now I understand what you intend to do. I wonder if there are cases when this would fail. An extreme case will be that update is of type BaseSection and section is of type XRayDiffraction

Co-authored-by: Sarthak Kapoor <[email protected]>
@aalbino2
Copy link
Contributor Author

aalbino2 commented Dec 3, 2024

Okay, now I understand what you intend to do. I wonder if there are cases when this would fail. An extreme case will be that update is of type BaseSection and section is of type XRayDiffraction

Is XRayDiffraction a BaseSection ? If not, the statement will be false,

no issues, right?

@ka-sarthak
Copy link
Collaborator

ka-sarthak commented Dec 3, 2024

Yes, the if will be false in this case, and the real "merging" of quantities will start happening; I wonder if the function will break there. Maybe not. Will be worth testing ;)

@aalbino2
Copy link
Contributor Author

aalbino2 commented Dec 3, 2024

Yes, as soon as I have time I'll dive into writing a test and thinking to edge cases

@aalbino2
Copy link
Contributor Author

aalbino2 commented Dec 3, 2024

Ah, I see now that the old tests don't run. I guess the first step would be to get those to run.

which are the old tests not running @hampusnasstrom? I see 3.9-3.10-3.11 passing

@hampusnasstrom
Copy link
Collaborator

Ah, I see now that the old tests don't run. I guess the first step would be to get those to run.

which are the old tests not running @hampusnasstrom? I see 3.9-3.10-3.11 passing

@aalbino2 this was a comment on your original PR which did not pass the tests. Now you seem to have fixed it with Sarthak's suggestions.

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.

allow merge_section to merge child classes too
3 participants