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

Merge code improvements from Kokroo #280

Merged
merged 10 commits into from
Dec 23, 2024

Conversation

danielfromearth
Copy link
Collaborator

@danielfromearth danielfromearth commented Dec 23, 2024

This PR is a secondary step for a merge from a repository fork, in Pull Request #264. After merging the external fork to a NASA feature branch, this current PR from a NASA feature branch to develop runs the complete CI workflow.


📚 Documentation preview 📚: https://ncompare--280.org.readthedocs.build/en/280/

kokroo and others added 10 commits December 21, 2024 17:49
The Path() constructor already handles both str and Path types effectively.
Added a check to ensure the provided suffix starts with a dot (.), which is standard for file extensions.
This prevents the creation of invalid file paths with malformed suffixes (e.g., .txt vs txt).

Path(should_be_path).with_suffix(suffix) is directly applied, reducing the number of steps.
Combined checks for str, int, and tuple into a single isinstance call using a tuple of types.
This reduces redundancy, improves clarity and performance . The TypeError is preserved to handle unsupported types.

Added the correct return type (str).
This function is no longer needed.
The intersection() method can deal with arbitrary objects but it is not needed here since we coerce everything into a string.

The & operator works at a lower level and is faster and sufficient for strings
Improvements:

Avoid unnecessary double conversions to sets:
Previously, set(a_sorted) and set(b_sorted) were resorted. The optimized code directly converts sequence_a and sequence_b into sets for fast lookups, creates a union using the low level "|" operator and then creates a sorted set. Sorting is performed only once on the union of the sets (a_set | b_set), rather than sorting a_sorted, b_sorted, and their combined union separately.

Simplified membership checking:
The if conditions now directly check the presence of an item in the sets instead of redundant checks.

Removed unreachable error check:
The raise ValueError condition is unnecessary since all items in all_items are guaranteed to come from either a_set or b_set.

The input-output behavior remains consistent while achieving faster execution.
Readability and branching Improvements
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

Attention: Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.

Project coverage is 92.01%. Comparing base (01ec81d) to head (947bf47).
Report is 11 commits behind head on develop.

Files with missing lines Patch % Lines
ncompare/utils.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #280      +/-   ##
===========================================
- Coverage    92.30%   92.01%   -0.29%     
===========================================
  Files            6        6              
  Lines          442      426      -16     
===========================================
- Hits           408      392      -16     
  Misses          34       34              

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

@danielfromearth danielfromearth merged commit bbd970d into develop Dec 23, 2024
12 checks passed
@danielfromearth danielfromearth deleted the feature/kokroo-code-improvements branch December 23, 2024 15:12
@danielfromearth danielfromearth self-assigned this Dec 23, 2024
@kokroo
Copy link

kokroo commented Dec 23, 2024

@danielfromearth I just noticed that I didn't follow the branch naming scheme correctly. It should have started with "feature".
What should the base branch be for future PRs? I was assuming it is the "develop" branch.

Cheers!

@danielfromearth
Copy link
Collaborator Author

danielfromearth commented Dec 24, 2024

What should the base branch be for future PRs? I was assuming it is the "develop" branch.

@kokroo, It's totally fine the way you did it! Because of branch protection rules, I (or another admin) will need to create the destination's feature branch in this repository.

Happy Holidays!

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