-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sourcery refactored master branch #1
base: main
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.
n = 1. + delta * (rho / RHO0) | ||
return n | ||
return 1. + delta * (rho / RHO0) |
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 refractive_index
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
def atmosphere(H_gp): # class StandardAtmosphere | ||
def atmosphere(H_gp): # class StandardAtmosphere |
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 atmosphere
refactored with the following changes:
- Ensure constant in comparison is on the right [×7] (
flip-comparison
)
dM = rho * np.sqrt(rh * rh + rhp * rhp - 2 * rh * rhp * cos_delphi) | ||
return dM | ||
return rho * np.sqrt(rh * rh + rhp * rhp - 2 * rh * rhp * cos_delphi) |
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 Kivalov07.delM
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
else: | ||
data = np.array(cosort(phase, *data)) | ||
data = np.array(cosort(phase, *data)) | ||
|
||
phase = data[0] | ||
data = data[1:] | ||
return phase, data | ||
phase = data[0] | ||
data = data[1:] | ||
return phase, 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 rephase
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
for i, line in enumerate(fp): | ||
for line in fp: |
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 iter_lines
refactored with the following changes:
- Remove unnecessary calls to
enumerate
when the index is not used (remove-unused-enumerate
)
if not self in ax.collections: | ||
if self not in ax.collections: |
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 ApertureCollection.add_to_axes
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
if radii.size: | ||
return [list(zip((r, r), (0, 1))) for r in radii] | ||
else: | ||
return [] | ||
return [list(zip((r, r), (0, 1))) for r in radii] if radii.size 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 ApLineCollection.make_segments
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if not self.size: | ||
concatenate = lambda o, a: a | ||
# HACK! if the Collection was initialized as empty, set the new properties as current | ||
else: | ||
concatenate = PropertyManager.concatenate | ||
|
||
concatenate = PropertyManager.concatenate if self.size else (lambda o, a: a) |
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 InteractionMixin.append
refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression
) - Replace if statement with if expression (
assign-if-exp
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
This removes the following comments ( why? ):
# HACK! if the Collection was initialized as empty, set the new properties as current
if not relative_motion is None: | ||
if relative_motion is not 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 InteractionMixin.resize
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
if instance is None: | ||
return self | ||
return getattr(instance, self.name) | ||
return self if instance is None else getattr(instance, self.name) |
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 CalibrationImage.__get__
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
frame_kws.update(frame) | ||
frame_kws |= frame |
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 plot_transformed_image
refactored with the following changes:
- Merge dictionary updates via the union operator (
dict-assign-update-to-union
)
if not image.__class__.__name__ == 'SkyImage': | ||
if image.__class__.__name__ != 'SkyImage': |
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 MosaicPlotter.plot_image
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
_kws.update(self.label_props) | ||
_kws |= self.label_props |
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 MosaicPlotter.label_image
refactored with the following changes:
- Merge dictionary updates via the union operator (
dict-assign-update-to-union
)
if (p is None) or (p == ()): | ||
# default parameter values for evaluation | ||
return np.zeros(self.dof) | ||
return p | ||
return np.zeros(self.dof) if (p is None) or (p == ()) else p |
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 MultivariateGaussians._check_params
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
This removes the following comments ( why? ):
# default parameter values for evaluation
else: | ||
if (grid.ndim != 3) or (grid.shape[-1] != self.n_dims): | ||
raise ValueError('Invalid grid') | ||
elif (grid.ndim != 3) or (grid.shape[-1] != self.n_dims): | ||
raise ValueError('Invalid grid') |
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 MultivariateGaussians.plot
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
)
if seg is None: # called from class | ||
return self | ||
|
||
# bind this class to the seg instance from whence the lookup came. | ||
# Essentially this binds the first argument `seg` in `__call__` below | ||
return types.MethodType(self, seg) | ||
return self if seg is None else types.MethodType(self, seg) |
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 MaskedStatistic.__get__
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
This removes the following comments ( why? ):
# bind this class to the seg instance from whence the lookup came.
# Essentially this binds the first argument `seg` in `__call__` below
# called from class
s.update(zip(self.labels, SegmentationImage.slices.fget(self))) | ||
s |= zip(self.labels, SegmentationImage.slices.fget(self)) |
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 slices
refactored with the following changes:
- Merge dictionary updates via the union operator (
dict-assign-update-to-union
)
if len(self.labels): | ||
return super().max_label | ||
else: | ||
# otherwise `np.max` borks with empty sequence | ||
return 0 | ||
return super().max_label if len(self.labels) else 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 max_label
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
This removes the following comments ( why? ):
# otherwise `np.max` borks with empty sequence
raise ValueError('Invalid label(s): %s' % str(tuple(invalid))) | ||
raise ValueError(f'Invalid label(s): {tuple(invalid)}') |
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 has_labels
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Remove unnecessary calls to
str()
from formatted values in f-strings (remove-str-from-fstring
)
if np.ma.is_masked(image): | ||
# ignore masked pixels | ||
seg_data = self.data.copy() | ||
seg_data[image.mask] = masked_pixels_label | ||
# this label will not be used for statistic computation | ||
return seg_data | ||
else: | ||
if not np.ma.is_masked(image): | ||
return self.data | ||
# ignore masked pixels | ||
seg_data = self.data.copy() | ||
seg_data[image.mask] = masked_pixels_label | ||
# this label will not be used for statistic computation | ||
return seg_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 _relabel_masked
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
d = {4: 1, 8: 2}.get(connectivity) | ||
if d: | ||
if d := {4: 1, 8: 2}.get(connectivity): |
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 dilate
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
assert origin in (0, 1) | ||
assert origin in {0, 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 format_term
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Use set when checking membership of a collection of literals (
collection-into-set
) - Move setting of default value for variable into
else
branch (introduce-default-else
)
raise ValueError('Invalid edge_cutoffs %s' % edge_cutoffs) | ||
raise ValueError(f'Invalid edge_cutoffs {edge_cutoffs}') |
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 make_border_mask
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
if deblend and not no_sources: | ||
if deblend: |
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 detect
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
# check if we are done. Jacob's stopping criterion | ||
done = (current == start).all() and (mv == (0, -1)).all() | ||
if done: | ||
if done := (current == start).all() and (mv == (0, -1)).all(): |
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 trace_boundary
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
This removes the following comments ( why? ):
# check if we are done. Jacob's stopping criterion
dtype = [] | ||
for key in keys: | ||
dtype.append( | ||
self._adapt_dtype(self.models[key], ()) | ||
) | ||
return dtype | ||
return [self._adapt_dtype(self.models[key], ()) for key in 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 CompoundModel.get_dtype
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Convert for loop into list comprehension (
list-comprehension
)
if out_shape == 1: | ||
out_shape = () | ||
else: | ||
out_shape = int2tup(out_shape) | ||
|
||
out_shape = () if out_shape == 1 else int2tup(out_shape) | ||
dt = model.get_dtype() | ||
if len(dt) == 1: # simple model | ||
name, base, dof = dt[0] | ||
dof = int2tup(dof) | ||
# extend shape of dtype | ||
return model.name, base, out_shape + dof | ||
else: # compound model | ||
if len(dt) != 1: | ||
# structured dtype - nest! | ||
return model.name, dt, out_shape | ||
name, base, dof = dt[0] | ||
dof = int2tup(dof) | ||
# extend shape of dtype | ||
return model.name, base, out_shape + dof |
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 CompoundModel._adapt_dtype
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
This removes the following comments ( why? ):
# compound model
# simple model
self.logger.debug('Guessed: (%s)' % ', '.join(map(decimal_repr, p0))) | ||
self.logger.debug(f"Guessed: ({', '.join(map(decimal_repr, p0))})") |
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 lmMixin.fit
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Use named expression to simplify assignment and conditional (
use-named-expression
)
This removes the following comments ( why? ):
# model "converged" to the initial values
def __new__(meta, name, bases, namespace): | ||
def __new__(cls, name, bases, namespace): | ||
for base in bases: | ||
for mn, method in inspect.getmembers(base, inspect.isfunction): | ||
if (mn in method_names): | ||
# decorate the method | ||
namespace[mn] = convert_params(method) | ||
return type.__new__(meta, name, bases, namespace) | ||
return type.__new__(cls, name, bases, namespace) |
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 lmModelFactory.lmConvertMeta.__new__
refactored with the following changes:
- The first argument to class methods should be
cls
(class-method-first-arg-name
)
if isinstance(data, Parameters): | ||
return data.npar | ||
else: | ||
return np.shape(data) | ||
return data.npar if isinstance(data, Parameters) else np.shape(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 get_shape
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.05%.
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
master
refactored 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
master
branch, then run:Help us improve this pull request!