-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
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
base: master
Are you sure you want to change the base?
Conversation
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.
Due to GitHub API limits, only the first 60 comments can be shown.
| get_abbreviations = dict((i[0], [j.lstrip() for j in i[1].split(",")]) for i in get_abbreviations) | ||
| get_abbreviations = { | ||
| i[0]: [j.lstrip() for j in i[1].split(",")] for i in get_abbreviations | ||
| } | ||
|
|
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.
Function read_abbreviations refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
| if not 'dialect' in block: | ||
| if 'dialect' not in block: |
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.
Function ImportHelper.extract_add_dialect_block refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| if filter == None: | ||
| filter = dict() | ||
| if filter is None: | ||
| filter = {} |
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.
Function ImportHelper.from_folder refactored with the following changes:
- Use x is None rather than x == None (
none-compare) - Replace if statement with if expression (
assign-if-exp) - Replace dict() with {} (
dict-literal)
This removes the following comments ( why? ):
# append subsequent minfos
| if not len(splits[0].split("_")) == 4: | ||
| if len(splits[0].split("_")) != 4: |
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.
Function ImportHelper.from_file refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Simplify if expression by using or (
or-if-exp-identity) - Simplify logical expression using De Morgan identities (
de-morgan)
| if series is not None: | ||
| # if only one series and not three | ||
| if len(series) == 3 and not len(series[0]) == 3: | ||
| series = tuple2list_of_tuples(to_tuple(series)) | ||
| if series is not None and len(series) == 3 and len(series[0]) != 3: | ||
| series = tuple2list_of_tuples(to_tuple(series)) |
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.
Function ImportHelper.__init__ refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs) - Simplify logical expression using De Morgan identities (
de-morgan)
This removes the following comments ( why? ):
# if only one series and not three
| """ | ||
|
|
||
| return True if result in self._results.keys() else False | ||
| return result in self._results.keys() |
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.
Function Measurement.has_result refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity)
| add = 'mean_' | ||
| else: | ||
| add = '' | ||
| add = 'mean_' if self.is_mean else '' |
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.
Function Measurement.__repr__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| def reset_data(self): # todo rewrite new data pandas | ||
| def reset_data(self): # todo rewrite new data pandas | ||
| """ | ||
| Resets all data back to the original state. Deepcopies _raw_data back to _data and resets correction | ||
| """ | ||
| midx = self.__class__._mids.index(self.mid) | ||
|
|
||
| self.log().debug(f'Resetting the data') | ||
| self.log().debug('Resetting the data') |
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.
Function Measurement.reset_data refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| return True if self.initial_state else False | ||
| return bool(self.initial_state) |
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.
Function Measurement.has_initial_state refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity)
| else: | ||
| series = (None, np.nan, None) # no series | ||
| return [series] | ||
| series = (None, np.nan, None) # no series | ||
| return [series] |
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.
Function Measurement.series refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if sval is not None: | ||
| sval = to_tuple(sval) | ||
| if method == 'all': | ||
| return True if all(i in self.svals for i in sval) else False | ||
| if method == 'any': | ||
| return True if any(i in self.svals for i in sval) else False | ||
| if method == 'none': | ||
| return True if not any(i in self.svals for i in sval) else False | ||
| else: | ||
| return True if not self.svals else False | ||
| if sval is None: | ||
| return not self.svals | ||
| sval = to_tuple(sval) | ||
| if method == 'all': | ||
| return all(i in self.svals for i in sval) | ||
| if method == 'any': | ||
| return any(i in self.svals for i in sval) | ||
| if method == 'none': | ||
| return all(i not in self.svals for i in sval) |
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.
Function Measurement.has_sval refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity) - Invert any/all to simplify comparisons (
invert-any-all) - Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if stype is not None: | ||
| stype = to_tuple(stype) | ||
| if method == 'all': | ||
| return True if all(i in self.stypes for i in stype) else False | ||
| if method == 'any': | ||
| return True if any(i in self.stypes for i in stype) else False | ||
| if method == 'none': | ||
| return True if not any(i in self.stypes for i in stype) else False | ||
| else: | ||
| return True if not self.stypes else False | ||
| if stype is None: | ||
| return not self.stypes | ||
| stype = to_tuple(stype) | ||
| if method == 'all': | ||
| return all(i in self.stypes for i in stype) | ||
| if method == 'any': | ||
| return any(i in self.stypes for i in stype) | ||
| if method == 'none': | ||
| return all(i not in self.stypes for i in stype) |
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.
Function Measurement.has_stype refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity) - Invert any/all to simplify comparisons (
invert-any-all) - Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if series is not None: | ||
| series = tuple2list_of_tuples(series) | ||
| if method == 'all': | ||
| return True if all(i in self.series for i in series) else False | ||
| if method == 'any': | ||
| return True if any(i in self.series for i in series) else False | ||
| if method == 'none': | ||
| return True if not any(i in self.svals for i in series) else False | ||
| else: | ||
| return True if self._series else False | ||
| if series is None: | ||
| return bool(self._series) | ||
| series = tuple2list_of_tuples(series) | ||
| if method == 'all': | ||
| return all(i in self.series for i in series) | ||
| if method == 'any': | ||
| return any(i in self.series for i in series) | ||
| if method == 'none': | ||
| return all(i not in self.svals for i in series) |
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.
Function Measurement.has_series refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity) - Invert any/all to simplify comparisons (
invert-any-all) - Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| otherseries = (s for s in other.series if not s[0] in ignore_stypes) | ||
|
|
||
| if all(i in otherseries for i in selfseries): | ||
| return True | ||
| otherseries = (s for s in other.series if s[0] not in ignore_stypes) | ||
|
|
||
| else: | ||
| return False | ||
| return all(i in otherseries for i in selfseries) |
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.
Function Measurement.equal_series refactored with the following changes:
- Simplify conditional into return statement (
return-identity) - Simplify logical expression using De Morgan identities (
de-morgan)
| norm_initial_state=True, **options): # todo check if works | ||
| norm_initial_state=True, **options): # todo check if works |
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.
Function Measurement.normalize refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| info.loc[self.name, 'sample groups'] = self._samplegroups if self._samplegroups else 'None' | ||
| info.loc[self.name, 'sample groups'] = self._samplegroups or 'None' | ||
|
|
||
| mtypes = [(mt, len(self.get_measurement(mtype=mt))) for mt in self.mtypes] | ||
|
|
||
| if mtypes: | ||
| info.loc[self.name, 'mtypes'] = ', '.join(self.mtypes) # if len(mtypes) > 1 else mtypes[0] | ||
| else: | ||
| info.loc[self.name, 'mtypes'] = None | ||
|
|
||
| info.loc[self.name, 'mtypes'] = ', '.join(self.mtypes) if mtypes else None |
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.
Function Sample.info refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Simplify if expression by using or (
or-if-exp-identity)
This removes the following comments ( why? ):
# if len(mtypes) > 1 else mtypes[0]
| if self.samplegroups: | ||
| sgroups = self.samplegroups | ||
| else: | ||
| sgroups = None | ||
|
|
||
| sgroups = self.samplegroups or None | ||
| """ DATA import from mass, height, diameter, len ... """ | ||
|
|
||
| # check for parameters in kwargs (i.e. mass = '12mg' | ||
| parameters = ['mass', 'diameter', 'height', 'x_len', 'y_len', 'z_len'] | ||
| if create_parameters: | ||
| if any([(k in parameters) and (kwargs[k] is not None) for k in kwargs.keys()]): | ||
| # check for parameters in kwargs (i.e. mass = '12mg' | ||
| parameters = ['mass', 'diameter', 'height', 'x_len', 'y_len', 'z_len'] | ||
| if any( | ||
| (k in parameters) and (kwargs[k] is not None) | ||
| for k in kwargs.keys() | ||
| ): |
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.
Function Sample.add_measurement refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Simplify if expression by using or (
or-if-exp-identity) - Replace unneeded comprehension with generator (
comprehension-to-generator) - Move assignments closer to their usage (
move-assign)
| return set(series for m in self.measurements for series in m.series) | ||
| return {series for m in self.measurements for series in m.series} |
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.
Function Sample.series refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
| return set(stype for m in self.measurements for stype in m.stypes if stype) | ||
| return {stype for m in self.measurements for stype in m.stypes if stype} |
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.
Function Sample.stypes refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
| return set(series[1] for series in self.series | ||
| if isinstance(series[1], (int, float)) | ||
| if not np.isnan(series[1])) | ||
| return {series[1] for series in self.series | ||
| if isinstance(series[1], (int, float)) | ||
| if not np.isnan(series[1])} |
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.
Function Sample.svals refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
| return set(series[2] for series in self.series) | ||
| return {series[2] for series in self.series} |
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.
Function Sample.sunits refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
| return set(m.mtype for m in self.measurements) | ||
| return {m.mtype for m in self.measurements} |
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.
Function Sample.mtypes refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
| svals = set(sval for m in self.mean_measurements for sval in m.svals) | ||
| svals = {sval for m in self.mean_measurements for sval in m.svals} |
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.
Function Sample._convert_sval_range refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
| if not name: | ||
| self.name = time.strftime("%Y%m%d:%H%M") | ||
| else: | ||
| self.name = name | ||
|
|
||
| self.name = time.strftime("%Y%m%d:%H%M") if not name else name | ||
| # create empty dictionary for storing samples | ||
| self._samples = dict() # {'sname':'sobj'} | ||
| self._samples = {} |
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.
Function Study.__init__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Replace dict() with {} (
dict-literal)
This removes the following comments ( why? ):
# {'sname':'sobj'}
| for s in sorted(self._samples.values()): | ||
| yield s | ||
| yield from sorted(self._samples.values()) |
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.
Function Study.__iter__ refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from)
| idx = i | ||
|
|
||
| if not idx == len(item) - 1: | ||
| if idx != len(item) - 1: |
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.
Function split_num_alph refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| else: | ||
| xyz = args[0] | ||
|
|
||
| xyz = kwargs.pop('xyz') if 'xyz' in kwargs else args[0] |
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.
Function import_submodules.handle_shape_dtype.conversion refactored with the following changes:
- Simplify conditional into switch-like form (
switch) - Swap positions of nested conditionals (
swap-nested-ifs) - Merge nested if conditions (
merge-nested-ifs) - Replace if statement with if expression (
assign-if-exp)
| if not any(i == 3 for i in s): | ||
| if all(i != 3 for i in s): | ||
| raise ValueError('At least one dimension needs to be length 3') | ||
| # for [x,y,z] or [d,i,m] | ||
| if s == (3,): | ||
| if len(set(np.shape(elem) for elem in xyz)) != 1: | ||
| if len({np.shape(elem) for elem in xyz}) != 1: | ||
| raise ValueError('Number of elements ix xyz is inconsistent') | ||
| xyz = np.array(xyz).reshape((1, 3)) | ||
|
|
||
| # for array like [[x1,x2,... ],[y1,y2,...],[z1,z2,...]], |
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.
Function import_submodules.maintain_n3_shape refactored with the following changes:
- Invert any/all to simplify comparisons (
invert-any-all) - Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
This removes the following comments ( why? ):
# for array like [[x1,x2,... ],[y1,y2,...],[z1,z2,...]],
| else: | ||
| level = int(row[num_index:6]) | ||
|
|
||
| level = 0 if not row[num_index:6] else int(row[num_index:6]) |
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.
Function Cif._separate_row refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| corrected = sample_means - holder_means | ||
| return corrected | ||
| return sample_means - holder_means |
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.
Function Cif._correct_holder refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.58%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
masterrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run:Help us improve this pull request!