-
Notifications
You must be signed in to change notification settings - Fork 15
Sledgehammer pass at refactoring units #1552
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main-dev #1552 +/- ##
============================================
- Coverage 78.11% 77.47% -0.64%
============================================
Files 145 141 -4
Lines 21579 20852 -727
============================================
- Hits 16856 16155 -701
+ Misses 4723 4697 -26
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
from pyaerocom.helpers import ( | ||
get_lowest_resolution, | ||
isnumeric, | ||
make_datetime_index, | ||
to_pandas_timestamp, |
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.
same here, surprising indeed that the import works
@@ -23,11 +23,10 @@ | |||
VariableDefinitionError, | |||
VariableNotFoundError, | |||
) | |||
from pyaerocom.units.datetime import cftime_to_datetime64, datetime2str | |||
from pyaerocom.helpers import ( |
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.
one here too
pyaerocom/colocation/colocator.py
Outdated
from pyaerocom.helpers import ( | ||
get_lowest_resolution, | ||
start_stop, | ||
to_datestring_YYYYMMDD, | ||
to_pandas_timestamp, |
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.
here too
@@ -7,8 +7,8 @@ | |||
from pyaerocom import const | |||
from pyaerocom.aeroval.modelentry import ModelEntry | |||
from pyaerocom.griddeddata import GriddedData | |||
from pyaerocom.units.datetime import get_highest_resolution | |||
from pyaerocom.helpers import ( |
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.
here is the import, sorry, I deleted a comment which was in the wrong file
def __radd__(self, other) -> MolecularMass: | ||
return self.__add__(other) | ||
|
||
def __sub__(self, other) -> MolecularMass: | ||
if isinstance(other, MolecularMass): |
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.
to improve coverage would it be possible to add some dummy testing here, something like
def test_molecular_mass___sub___and___mul__():
mass = MolecularMass("H2")
mass2 = MolecularMass("O")
assert mass2.__sub__(mass).mass == 13.983519999999999
assert mass.__mul__(mass2) == 32.252870472
?
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.
coverage aside, I have no other comments otherwise, so I'll approve
return str(self.val) | ||
|
||
|
||
def sort_ts_types(ts_types: list[str | TsType]) -> list[str]: |
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.
Out of scope for this PR but it would be nice if all occurrences of time series types in pyaerocom were instances of TsType
Change Summary
A very rough attempt at collecting units related code in a new
units
submodule. For now this is mainly focused on moving existing code, not improving the code (I'll leave that to a second PR to make the reviews manageable). That being said, I've adressed a couple of low hanging fruits:@total_ordering
decorator.sort_ts_types
,get_lowest_resolution
,get_highest_resolution
using Python's built insorted()
.calendar.isleap()
to avoid Y2.1k problems :P_concprcp_units_helpers.py
since it isn't used (?). Most functions have raised NotImplementedErrors for ~3 years.MolecularMass
class to represent molar mass.Overview of moved things
pyaerocom/units_helpers.py
->pyaerocom/units/units_helpers.py
pyaercom/helpers.py
split betweenpyaercom/units/datetime/utils.py
andpyaerocom/units/helpers.py
pyaerocom/time_config.py
->pyaerocom/units/datetime/_time_config.py
pyaerocom/molmasses.py
->pyaerocom/units/molecularmass.py
Related issue number
related to #1512
Checklist