-
Notifications
You must be signed in to change notification settings - Fork 11
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
Spectrum refactoring, Spectrum2DCollection #305
Conversation
53d8b77
to
92b3af4
Compare
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #305 +/- ##
==========================================
- Coverage 95.85% 95.47% -0.39%
==========================================
Files 28 28
Lines 3982 4021 +39
Branches 803 816 +13
==========================================
+ Hits 3817 3839 +22
- Misses 97 109 +12
- Partials 68 73 +5 ☔ View full report in Codecov by Sentry. |
8a5a1d0
to
58306c3
Compare
- This version of select() should be more robust in dealing with parameters that exist in "top level" of metadata dict - I hope it is also easier to understand
Some of this was done in another branch, and this one rebased
This adds toolz as a dependency to the main package. We don't anticipate that causing a lot of problems; it is a small, stable, pure-python library also available on conda-forge.
Linters hate the named lambdas. I think they are quite nice because they are compact and immediately draw attention to the "one-liner" they attach a name to... but maybe the more explicit form with type hints will make it easier for someone to understand in future.
This structure seems a bit more legible and should reduce redundancy in Spectrum2DCollection
Collect the axis-twiddling code in one place to improve readability.
- Refactor re-used data import to use pytest fixture - Remove initial from_spectra test; new one covers it all - Test from_spectra with inconsistent input - Test mixin-supplied methods
58306c3
to
56dfcb9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few code-style questions. Functionally, I'm trusting it's good.
Make things a little cleaner and more idiomatic Co-authored-by: Jacob Wilkins <[email protected]>
euphonic/spectra.py
Outdated
select_key_values = dict( | ||
(key, (value,)) if isinstance(value, (int, str)) else (key, value) | ||
for key, value in select_key_values.items() | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, you've got toolz
does this mean we could do this with a mapvalues
?
- This avoids some of the repetition in dict comprehensions to remove an element - Here we also slightly rework _combine_metadata so it is clearer what each variable represents.
list comprehension is little clunky but avoids the 1-length special case: cleaner overall
Via discussion / pair-programming with @oerc0122 - Use native dict comprehension over keyfilter in iter_metadata: it's a bit ugly but no more complicated, and should be easier to read "casually" - Clearer comment re: value-pair combination - Replace a lambda with named partial function and toolz complement
Co-authored-by: Jacob Wilkins <[email protected]>
As part of a major refactor of Abins, we would like to use a Spectrum2DCollection object which behaves similarly to Spectrum1DCollection. This allows the code to largely treat 1D and 2D data interchangably, simplifying the logic and providing access to select/groupby "table-like" operations on the data.
This is implemented by factoring out the "collection"-specific methods to a "mixin" class. This gives a reasonable class heirarchy in which Spectrum1D, Spectrum2D, Spectrum1DCollection and Spectrum2DCollection are all children of Spectrum but not of each other.
In the process, we also found some limitations and inefficiencies in the existing Spectrum objects:
iter_metadata
method that iterates over metadata lines, merging the top-level and "line-data" parts on the fly. This is also a good building block to simplify some of the other metadata-handling methods.