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

Tidy up euphonic.spectra: split into multiple files and lint #359

Merged
merged 15 commits into from
Jan 24, 2025

Conversation

ajjackson
Copy link
Collaborator

Closes #358

@ajjackson
Copy link
Collaborator Author

Hmm, at the moment git-blame from the github interface is succesfully tracking the history of lines in spectra.base, but not in spectra.collecions 😞

Copy link

codecov bot commented Jan 23, 2025

Codecov Report

Attention: Patch coverage is 97.47899% with 9 lines in your changes missing coverage. Please review.

Project coverage is 96.03%. Comparing base (63a7bdd) to head (78d756f).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
euphonic/spectra/collections.py 97.14% 7 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #359      +/-   ##
==========================================
+ Coverage   95.44%   96.03%   +0.58%     
==========================================
  Files          29       31       +2     
  Lines        4218     4209       -9     
  Branches      643      641       -2     
==========================================
+ Hits         4026     4042      +16     
+ Misses        114       95      -19     
+ Partials       78       72       -6     

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

Copy link
Contributor

github-actions bot commented Jan 23, 2025

Test Results

    17 files   -   1      17 suites   - 1   1h 0m 15s ⏱️ - 2m 58s
 1 078 tests +  9   1 072 ✅ +  9   6 💤 ± 0  0 ❌ ±0 
10 295 runs   - 182  10 242 ✅  - 172  53 💤  - 10  0 ❌ ±0 

Results for commit 78d756f. ± Comparison against base commit 63a7bdd.

This pull request removes 2 and adds 11 tests. Note that renamed tests count towards both.
euphonic_test.test_spectrum2dcollection.TestSpectrum2DCollectionCreation ‑ test_from_bad_spectra
euphonic_test.test_spectrum2dcollection.TestSpectrum2DCollectionCreation ‑ test_from_bad_spectra_usafe
euphonic_test.test_spectrum1dcollection.TestSpectrum1DCollectionCreation ‑ test_create_from_bad_sequence[input_spectra3-ValueError]
euphonic_test.test_spectrum1dcollection.TestSpectrum1DCollectionCreation ‑ test_create_from_bad_sequence[input_spectra4-ValueError]
euphonic_test.test_spectrum1dcollection.TestSpectrum1DCollectionMethods ‑ test_broaden_bad_width
euphonic_test.test_spectrum2dcollection.TestSpectrum2DCollectionCreation ‑ test_from_bad_spectra[inconsistent_x_item-]
euphonic_test.test_spectrum2dcollection.TestSpectrum2DCollectionCreation ‑ test_from_bad_spectra[inconsistent_x_length_item-]
euphonic_test.test_spectrum2dcollection.TestSpectrum2DCollectionCreation ‑ test_from_bad_spectra[inconsistent_x_tick_labels_item-]
euphonic_test.test_spectrum2dcollection.TestSpectrum2DCollectionCreation ‑ test_from_bad_spectra[inconsistent_x_units_item-]
euphonic_test.test_spectrum2dcollection.TestSpectrum2DCollectionCreation ‑ test_from_bad_spectra[inconsistent_y_item-]
euphonic_test.test_spectrum2dcollection.TestSpectrum2DCollectionCreation ‑ test_from_bad_spectra[inconsistent_z_units_item-Spectrum units in sequence are inconsistent]
euphonic_test.test_spectrum2dcollection.TestSpectrum2DCollectionCreation ‑ test_from_bad_spectra_unsafe
…

♻️ This comment has been updated with latest results.

@ajjackson
Copy link
Collaborator Author

Second-time lucky! The trick was to "move" the initial file on separate branches and then merge the branches.

@ajjackson
Copy link
Collaborator Author

See #360 for why a pylint warning is suppressed, related to a changing function signature.

@ajjackson ajjackson marked this pull request as ready for review January 23, 2025 15:11
@ajjackson ajjackson requested a review from oerc0122 January 23, 2025 16:37
Copy link
Collaborator

@oerc0122 oerc0122 left a comment

Choose a reason for hiding this comment

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

Only major thing is to watch out for shadowing.

I suggest that updates porting the typing to 3.10 style is a separate PR or done through Boy Scout Rule.

euphonic/spectra/base.py Show resolved Hide resolved
euphonic/spectra/base.py Show resolved Hide resolved
euphonic/spectra/base.py Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

Be careful, as this module shadows the collections stdlib module within this folder.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am assuming this is mostly unmodified from the original. If anything's changed, can you highlight it for me?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The diff seems to be working correctly, which is nice! We want to not squash this branch to make sure that keeps working. I'll do a bit of interactive rebasing (i.e. reordering and squashing) to keep the introduced history somewhat manageable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Which shadowing scenarios should we worry about? Even in spectra.__init__.py we can from collections import abc and cannot from collections import Spectrum1DCollection. It looks like the euphonic.spectra namespace is keeping things isolated properly.

I suppose in some other file somebody could from euphonic.spectra import collections but I don't think that will pollute other modules unexpectedly? I can even do it in euphonic/__init__.py without breaking tests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For me it's saying that the entire file has changed (which is true) and I wasn't going to read through every line.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For me it's saying that the entire file has changed (which is true) and I wasn't going to read through every line.

That's odd. I get the folded "large diff" buttons
[screenshot]
which unfold to a proper diff
[screenshot]
I appreciate there's a lot there though, I'm doing a scout of commit history to see if there are any significant changes worth bringing extra attention to.

Note I'm referring to collections.py not base.py

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interestingly if in spectra/init.py I try

from . import collections
from collections import Spectrum1DCollection

the first import works and the second one fails; somehow stdlib took priority!

Yeah, the issue I had was from starting the Python interpreter/having PYTHONPATH in the folder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note I'm referring to collections.py not base.py

Gotcha, that one has working blame but diff is less helpful

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, the issue I had was from starting the Python interpreter/having PYTHONPATH in the folder.

Ah yes, there could be a problem if running things from inside the spectra folder, I hadn't thought about that. I don't expect it will happen to me but it might happen to someone and be quite painful to figure out.

I suppose it could be named spectrum_collection then. Or just collection but that's asking for problems with typos...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that provided there's awareness, that's a good start. I'm happy for this to go in.

meson.build Show resolved Hide resolved
These are mostly pre-existing issues

I can't do much about the "too many arguments" on broadening methods
as this is established API and would be a breaking change.
We can't fix this until v2 because it would be an API break
- Add missing "bad sequence" cases for Spectrum1DCollection
- check bad broadening type in Spectrum1DCollection
- Fix typo in test name for Spectrum2DCollection
- Add a missing test docstring
- Restore lost docstring parameter to assert_regular_bins
Co-authored-by: Jacob Wilkins <[email protected]>
@ajjackson
Copy link
Collaborator Author

ajjackson commented Jan 24, 2025

That's interesting, this windows test failure looks similar to the ones we see on Conda-forge https://github.com/pace-neutrons/Euphonic/actions/runs/12948116067/job/36116091358?pr=359#logs

And it passes on a re-run 😞 . There seems to be something flaky/non-deterministic going on? But it only ever happens on Windows.

Copy link
Collaborator

@oerc0122 oerc0122 left a comment

Choose a reason for hiding this comment

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

Happy for this to go in once you're happy with the tests, given we're aware of the risk of shadowing, I don't think it'll be a major concern like you say.

@ajjackson ajjackson merged commit d0d083d into master Jan 24, 2025
13 checks passed
@ajjackson
Copy link
Collaborator Author

Many thanks for review, appreciate this sort of refactor is never much fun to look at!

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.

Consider breaking up euphonic.spectra into submodules
2 participants