-
Notifications
You must be signed in to change notification settings - Fork 25
Sourcery refactored develop branch #544
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
| if isinstance(result, tuple): | ||
| data, (edgesx, edgesy) = result | ||
| return data, edgesx, edgesy | ||
| else: | ||
| if not isinstance(result, tuple): | ||
| return result | ||
|
|
||
| data, (edgesx, edgesy) = result | ||
| return data, edgesx, edgesy |
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 histogram2d refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if isinstance(result, tuple): | ||
| data, (edges,) = result | ||
| return data, edges | ||
| else: | ||
| if not isinstance(result, tuple): | ||
| return result | ||
|
|
||
| data, (edges,) = result | ||
| return data, edges |
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 histogram refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| elif options == {"circular", "underflow", "overflow"} or options == { | ||
| "circular", | ||
| "overflow", | ||
| }: | ||
| elif options in [ | ||
| {"circular", "underflow", "overflow"}, | ||
| { | ||
| "circular", | ||
| "overflow", | ||
| }, | ||
| ]: |
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 Regular.__init__ refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
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.
This should be a set. A set in a set... Has to be a frozenset... Well, okay.
| elif options == {"circular", "underflow", "overflow",} or options == { | ||
| "circular", | ||
| "overflow", | ||
| }: | ||
| elif options in [ | ||
| { | ||
| "circular", | ||
| "underflow", | ||
| "overflow", | ||
| }, | ||
| { | ||
| "circular", | ||
| "overflow", | ||
| }, | ||
| ]: |
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 Variable.__init__ refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| msg = "Developer shortcut: will be removed in a future version" | ||
| if isinstance(item, tuple) and len(item) == 3: | ||
| msg = "Developer shortcut: will be removed in a future version" |
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 _arg_shortcut refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| if self._hist.rank() == 1: | ||
| s = str(self._hist) | ||
| if self._hist.rank() != 1: | ||
| return repr(self) | ||
| s = str(self._hist) | ||
| # get rid of first line and last character | ||
| s = s[s.index("\n") + 1 : -1] | ||
| else: | ||
| s = repr(self) | ||
| return s | ||
| return s[s.index("\n") + 1 : -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 Histogram.__str__ refactored with the following changes:
- Lift return into if (
lift-return-into-if) - Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| self.axes = self._generate_axes_() | ||
|
|
||
| else: # Classic (0.10 and before) state | ||
| self._hist = state["_hist"] | ||
| self._variance_known = True | ||
| self.metadata = state.get("metadata", None) | ||
| for i in range(self._hist.rank()): | ||
| self._hist.axis(i).metadata = {"metadata": self._hist.axis(i).metadata} | ||
| self.axes = self._generate_axes_() | ||
|
|
||
| self.axes = self._generate_axes_() |
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 Histogram.__setstate__ refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| else: | ||
| projections = [i for i in range(self.ndim) if i not in integrations] | ||
| projections = [i for i in range(self.ndim) if i not in integrations] | ||
|
|
||
| return ( | ||
| self._new_hist(reduced.project(*projections)) | ||
| if projections | ||
| else reduced.sum(flow=True) | ||
| ) | ||
| return ( | ||
| self._new_hist(reduced.project(*projections)) | ||
| if projections | ||
| else reduced.sum(flow=True) | ||
| ) |
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 Histogram.__getitem__ refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if method == "__call__" and len(inputs) == 1: | ||
| if ufunc in {np.negative, np.positive}: | ||
| (result,) = kwargs.pop("out", [np.empty(self.shape, self.dtype)]) | ||
| if ( | ||
| method == "__call__" | ||
| and len(inputs) == 1 | ||
| and ufunc in {np.negative, np.positive} | ||
| ): | ||
| (result,) = kwargs.pop("out", [np.empty(self.shape, self.dtype)]) | ||
|
|
||
| ufunc(inputs[0]["value"], out=result["value"], **kwargs) | ||
| result["variance"] = inputs[0]["variance"] | ||
| return result.view(self.__class__) # type: ignore | ||
| ufunc(inputs[0]["value"], out=result["value"], **kwargs) | ||
| result["variance"] = inputs[0]["variance"] | ||
| return result.view(self.__class__) # type: ignore |
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 WeightedSumView.__array_ufunc__ refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
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.
Have to think about this one.
| if isinstance(name, str): | ||
| for i, ax in enumerate(self): | ||
| if ax.name == name: | ||
| return i | ||
| raise KeyError(f"{name} not found in axes") | ||
| else: | ||
| if not isinstance(name, str): | ||
| return name | ||
|
|
||
| for i, ax in enumerate(self): | ||
| if ax.name == name: | ||
| return i | ||
| raise KeyError(f"{name} not found in axes") |
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 NamedAxesTuple._get_index_by_name refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| ) | ||
| ) | ||
| elif all((a == b or a == 1) for a, b in zip(other.shape, self.shape)): | ||
| elif all(a in [b, 1] for a, b in zip(other.shape, self.shape)): |
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.
| elif all(a in [b, 1] for a, b in zip(other.shape, self.shape)): | |
| elif all(a in {b, 1} for a, b in zip(other.shape, self.shape)): |
| view = self.view(flow=False) | ||
| getattr(view, name)(other) | ||
| elif all((a == b or a == 1) for a, b in zip(other.shape, self.axes.extent)): | ||
| elif all(a in [b, 1] for a, b in zip(other.shape, self.axes.extent)): |
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.
| elif all(a in [b, 1] for a, b in zip(other.shape, self.axes.extent)): | |
| elif all(a in {b, 1} for a, b in zip(other.shape, self.axes.extent)): |
for more information, see https://pre-commit.ci
33e3ee9 to
0635d90
Compare
0635d90 to
0d3cbb8
Compare
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.23%.
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! Let us know what you think of it by mentioning @sourcery-ai in a comment. |
Branch
developrefactored 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
developbranch, then run: