-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery refactored master branch #103
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
| out_fname = "test_call_module.txt" | ||
| with clib.Session() as lib: | ||
| out_fname = "test_call_module.txt" |
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 test_call_module refactored with the following changes:
- Move assignments closer to their usage
pygmt/tests/test_clib.py
Outdated
| # Turns out wesn doesn't matter for Datasets | ||
| wesn = [0] * 6 | ||
| # Save the data to a file to see if it's being accessed correctly | ||
| with GMTTempFile() as tmp_file: | ||
| # Turns out wesn doesn't matter for Datasets | ||
| wesn = [0] * 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 test_put_vector refactored with the following changes:
- Move assignments closer to their usage
pygmt/tests/test_clib.py
Outdated
| # wesn doesn't matter for Datasets | ||
| wesn = [0] * 6 | ||
| # Save the data to a file to see if it's being accessed correctly | ||
| with GMTTempFile() as tmp_file: | ||
| # wesn doesn't matter for Datasets | ||
| wesn = [0] * 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 test_put_matrix refactored with the following changes:
- Move assignments closer to their usage
| vfargs = ( | ||
| "GMT_IS_DATASET|GMT_VIA_MATRIX", | ||
| "GMT_IS_POINT", | ||
| "GMT_IS_GRID", # The invalid direction argument | ||
| 0, | ||
| ) | ||
| with pytest.raises(GMTInvalidInput): | ||
| vfargs = ( | ||
| "GMT_IS_DATASET|GMT_VIA_MATRIX", | ||
| "GMT_IS_POINT", | ||
| "GMT_IS_GRID", # The invalid direction argument | ||
| 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 test_virtual_file_bad_direction refactored with the following changes:
- Move assignments closer to their usage
| size = 13 | ||
| x = list(range(0, size, 1)) | ||
| y = tuple(range(size, size * 2, 1)) | ||
| z = range(size * 2, size * 3, 1) | ||
| with clib.Session() as lib: | ||
| size = 13 | ||
| x = list(range(0, size, 1)) | ||
| y = tuple(range(size, size * 2, 1)) | ||
| z = range(size * 2, size * 3, 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 test_virtualfile_from_vectors_arraylike refactored with the following changes:
- Move assignments closer to their usage
| def mock_defaults(api, name, value): # pylint: disable=unused-argument | ||
| def mock_defaults(api, name, value): # pylint: disable=unused-argument | ||
| "Return an old version" | ||
| if name == b"API_VERSION": | ||
| value.value = b"5.4.3" | ||
| else: | ||
| value.value = b"bla" | ||
| value.value = b"5.4.3" if name == b"API_VERSION" else b"bla" |
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 test_fails_for_wrong_version.mock_defaults refactored with the following changes:
- Replace if statement with if expression
| for variable in product([None, data[:, 0]], repeat=3): | ||
| # Filter one valid configuration: | ||
| if not any(item is None for item in variable): | ||
| if all(item is not None for item in variable): |
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 test_contour_fail_no_data refactored with the following changes:
- Simplify inverted any() and all() calls
| specfile_contents = """ | ||
| with GMTTempFile() as specfile: | ||
|
|
||
| with open(specfile.name, "w") as file: | ||
| specfile_contents = """ |
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 test_legend_specfile refactored with the following changes:
- Move assignments closer to their usage
|
|
||
| showed = [fig for fig in SHOWED_FIGURES] | ||
| for _ in range(len(SHOWED_FIGURES)): | ||
| for SHOWED_FIGURE in SHOWED_FIGURES: |
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 test_pygmtscraper refactored with the following changes:
- Simplify generator expression
- Replace index in for loop with direct reference
f63f29d to
45abfc0
Compare
45abfc0 to
e0a5cc0
Compare
Sourcery Code Quality Report (beta)✅ Merging this PR will increase code quality in the affected files by 0.02 out of 10.
Here are some functions in these files that still need a tune-up:
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! |
| refs = set([r.strip() for r in refnames.strip("()").split(",")]) | ||
| refs = {r.strip() for r in refnames.strip("()").split(",")} | ||
| # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of | ||
| # just "foo-1.0". If we see a "tag: " prefix, prefer those. | ||
| TAG = "tag: " | ||
| tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)]) | ||
| tags = {r[len(TAG):] for r in refs if r.startswith(TAG)} |
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 git_versions_from_keywords refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator) - Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
| if line.strip().startswith(versionfile_source): | ||
| if "export-subst" in line.strip().split()[1:]: | ||
| present = True | ||
| if ( | ||
| line.strip().startswith(versionfile_source) | ||
| and "export-subst" in line.strip().split()[1:] | ||
| ): | ||
| present = 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 do_vcs_install refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| for i in range(3): | ||
| for _ in range(3): |
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 versions_from_parentdir refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| if pieces["dirty"]: | ||
| rendered += ".dirty" | ||
| else: | ||
| # exception #1 | ||
| rendered = "0+untagged.%d.g%s" % (pieces["distance"], | ||
| pieces["short"]) | ||
| if pieces["dirty"]: | ||
| rendered += ".dirty" | ||
| if pieces["dirty"]: | ||
| rendered += ".dirty" |
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 render_pep440 refactored with the following changes:
- Hoist conditional out of nested conditional (
hoist-if-from-if) - Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| if pieces["dirty"]: | ||
| rendered += ".dev0" | ||
| else: | ||
| # exception #1 | ||
| rendered = "0.post%d" % pieces["distance"] | ||
| if pieces["dirty"]: | ||
| rendered += ".dev0" | ||
| if pieces["dirty"]: | ||
| rendered += ".dev0" |
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 render_pep440_old refactored with the following changes:
- Hoist conditional out of nested conditional (
hoist-if-from-if) - Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| prefix = "pygmt-session" | ||
| with Session() as lib: | ||
| prefix = "pygmt-session" |
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 begin refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| code. | ||
| """ | ||
| image_names = list() | ||
| image_names = [] |
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 PyGMTScraper.__call__ refactored with the following changes:
- Replace list() with [] (
list-literal)
pygmt/clib/conversion.py
Outdated
| inc.append(coord_inc) | ||
|
|
||
| if any([i < 0 for i in inc]): # Sort grid when there are negative increments | ||
| if any(i < 0 for i in inc): # Sort grid when there are negative increments |
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 dataarray_to_matrix refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator)
| """ | ||
| arrays = [as_c_contiguous(np.asarray(i)) for i in vectors] | ||
| return arrays | ||
| return [as_c_contiguous(np.asarray(i)) for i in vectors] |
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 vectors_to_arrays refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| pad = 0 | ||
| else: | ||
| pad = self["GMT_PAD_DEFAULT"] | ||
| pad = 0 if "MATRIX" in family else self["GMT_PAD_DEFAULT"] |
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 Session._parse_pad refactored with the following changes:
- Swap positions of nested conditionals (
swap-nested-ifs) - Hoist repeated code outside conditional statement (
hoist-statement-from-if) - Replace if statement with if expression (
assign-if-exp)
| integer_value = sum(self[part] for part in parts) | ||
| return integer_value | ||
| return sum(self[part] for part in parts) |
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 Session._parse_constant refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if not all(len(i) == rows for i in arrays): | ||
| if any(len(i) != rows for i in arrays): |
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 Session.virtualfile_from_vectors refactored with the following changes:
- Invert any/all to simplify comparisons (
invert-any-all)
pygmt/datasets/earth_relief.py
Outdated
| valid_resolutions = ["01d"] | ||
| valid_resolutions.extend( | ||
| [f"{res:02d}m" for res in [60, 30, 20, 15, 10, 6, 5, 4, 3, 2, 1]] | ||
| ) | ||
| valid_resolutions.extend([f"{res:02d}s" for res in [30, 15]]) | ||
| valid_resolutions = [ | ||
| "01d", | ||
| *[f"{res:02d}m" for res in [60, 30, 20, 15, 10, 6, 5, 4, 3, 2, 1]], | ||
| *[f"{res:02d}s" for res in [30, 15]], | ||
| ] | ||
|
|
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 _is_valid_resolution refactored with the following changes:
- Merge extend into list declaration (
merge-list-extend)
| data = pd.read_csv( | ||
| return pd.read_csv( | ||
| fname, sep=r"\s+", names=["longitude", "latitude"], skiprows=1, comment=">" | ||
| ) | ||
| return 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 load_ocean_ridge_points refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| data = pd.read_csv( | ||
| return pd.read_csv( | ||
| fname, sep="\t", header=None, names=["longitude", "latitude", "bathymetry"] | ||
| ) | ||
| return 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 load_sample_bathymetry refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| size = 13 | ||
| x = list(range(0, size, 1)) | ||
| y = tuple(range(size, size * 2, 1)) | ||
| z = range(size * 2, size * 3, 1) | ||
| with clib.Session() as lib: | ||
| size = 13 | ||
| x = list(range(0, size, 1)) | ||
| y = tuple(range(size, size * 2, 1)) | ||
| z = range(size * 2, size * 3, 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 test_virtualfile_from_vectors_arraylike refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| def mock_defaults(api, name, value): # pylint: disable=unused-argument | ||
| def mock_defaults(api, name, value): # pylint: disable=unused-argument | ||
| "Return an old version" | ||
| if name == b"API_VERSION": | ||
| value.value = b"5.4.3" | ||
| else: | ||
| value.value = b"bla" | ||
| value.value = b"5.4.3" if name == b"API_VERSION" else b"bla" |
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 test_fails_for_wrong_version.mock_defaults refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| for variable in product([None, data[:, 0]], repeat=3): | ||
| # Filter one valid configuration: | ||
| if not any(item is None for item in variable): | ||
| if all(item is not None for item in variable): |
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 test_contour_fail_no_data refactored with the following changes:
- Invert any/all to simplify comparisons (
invert-any-all)
| specfile_contents = """ | ||
| with GMTTempFile() as specfile: | ||
|
|
||
| with open(specfile.name, "w") as file: | ||
| specfile_contents = """ |
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 test_legend_specfile refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
|
|
||
| showed = SHOWED_FIGURES.copy() | ||
| for _ in range(len(SHOWED_FIGURES)): | ||
| for SHOWED_FIGURE in SHOWED_FIGURES: |
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 test_pygmtscraper refactored with the following changes:
- Simplify generator expression (
simplify-generator) - Replace index in for loop with direct reference (
for-index-replacement)
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: