Repository navigation
fix ruff rule B007 violation in astropy/io - #17880
kangqiwang wants to merge 2 commits into
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
Hi, thanks for your work. I see you've been splitting this work into smaller chunks, and I assume you mean to divide it on a per-subpackage basis, however note that |
nstarman
left a comment
There was a problem hiding this comment.
Thanks for the PR @kangqiwang!
|
|
||
| for i, key in ( | ||
| for i, _ in ( | ||
| (i, x) |
There was a problem hiding this comment.
This can be simplified further by not packing x into the tuple.
| for spacer_line in itertools.islice(itertools.cycle(self.write_spacer_lines), self.start_line): | ||
| lines.append(spacer_line.copy()) |
There was a problem hiding this comment.
I think this can be simplified further to an extend()
| for spacer_line in itertools.islice(itertools.cycle(self.write_spacer_lines), self.start_line): | |
| lines.append(spacer_line.copy()) | |
| lines.extend([line.copy() for line in itertools.islice(itertools.cycle(self.write_spacer_lines), self.start_line)]) |
There was a problem hiding this comment.
Also, why adding the .copy() here? zip did not produce a copy...
| res = [] | ||
| for i in range(number): | ||
| for _ in range(number): | ||
| res.append(pickle.load(f)) |
There was a problem hiding this comment.
res = [pickle.load(f) for _ in range(number)]
| cy.representation_component_names | ||
| ) | ||
| for name in c.representation_component_names: | ||
| for _ in c.representation_component_names: |
There was a problem hiding this comment.
There must be a mistake in the the test. The next line should use name.
There was a problem hiding this comment.
I think that should be for attr in c.representation_component_names:.
Co-authored-by: Nathaniel Starkman <[email protected]>
| else: | ||
| for i, line in enumerate(self.process_lines(lines)): | ||
| if i == start_line: | ||
| self.names = next(self.splitter([line])) |
There was a problem hiding this comment.
Please revert, this is a code logic change and out of scope for a ruff PR.
| else: # No header line matching | ||
| raise ValueError("No header line found in table") | ||
|
|
||
| self.names = next(self.splitter([line])) |
There was a problem hiding this comment.
Please revert, this is a code logic change and out of scope for a ruff PR.
There was a problem hiding this comment.
⚖️ depends on one's perspective. How often do we actually look over these lines of code with a critical eye? In plenty of other ruff PRs we've embraced the opportunity to improve a line of code beyond the minimum level required to satisfy ruff.
There was a problem hiding this comment.
But if you want to make an Issue and do a follow up PR now that this has been spotted, that's the more procedurally correct thing.
OTOH, the logic elsewhere has often been "great! Someone wants to contribute and is using the ruff PR to also improve code = win/win".
🎣 with lint rules 🏋️♀️ with more substantial code improvements. 🤣
| for i, spacer_line in zip( | ||
| range(self.start_line), itertools.cycle(self.write_spacer_lines) | ||
| ): | ||
| lines.append(spacer_line) | ||
| for spacer_line in itertools.islice(itertools.cycle(self.write_spacer_lines), self.start_line): | ||
| lines.append(spacer_line.copy()) |
There was a problem hiding this comment.
Please avoid any code logic change in this ruff PR. Your changes should mostly be limited to either changing a loop variable to _, or in some cases eliminating an unnecessary enumerate.
| for col in cols: | ||
| for key, converters in self.converters.items(): | ||
| converters = [convert_numpy(col.dtype)] if col.dtype is not None else self.default_converters | ||
| for key, conv in self.converters.items(): | ||
| if fnmatch.fnmatch(col.name, key): | ||
| converters=conv | ||
| break | ||
| else: | ||
| if col.dtype is not None: | ||
| converters = [convert_numpy(col.dtype)] | ||
| else: | ||
| converters = self.default_converters | ||
|
|
There was a problem hiding this comment.
Not sure about the intent here, but please revert all these changes.
| break | ||
| else: # No header line matching | ||
| raise InconsistentTableError("No header line found in table") | ||
| return line | ||
| return line | ||
| raise InconsistentTableError("No header line found in table") |
| new_names.append(name[0]) | ||
| for i in range(1, int(name[1])): | ||
| for _ in range(int(name[1])-1): | ||
| # Add dummy columns |
There was a problem hiding this comment.
Revert to the original range(1, int(name[1]))).
| for col in self.columns: | ||
| idx += 1 |
There was a problem hiding this comment.
Here the preferred change would be to revert to the original enumerate but remove the unnecessary idx = 0 statement.
| ks = range(*key.indices(axis)) | ||
| data = [self[keys[:idx] + (k,) + keys[idx + 1 :]] for k in range(*key.indices(axis))] | ||
| break | ||
|
|
||
| if isiterable(key): | ||
| # Handle both integer and boolean arrays. | ||
| ks = np.arange(axis, dtype=int)[key] | ||
| data = [self[keys[:idx] + (k,) + keys[idx + 1 :]] for k in np.arange(axis, dtype=int)[key]] | ||
| break | ||
| # This should always break at some point if _getdata is called. | ||
|
|
||
| data = [self[keys[:idx] + (k,) + keys[idx + 1 :]] for k in ks] | ||
|
|
There was a problem hiding this comment.
Revert these changes, they are substantively changing the code and out of scope for this PR.
| cy.representation_component_names | ||
| ) | ||
| for name in c.representation_component_names: | ||
| for _ in c.representation_component_names: |
There was a problem hiding this comment.
I think that should be for attr in c.representation_component_names:.
|
Hi humans 👋 - this pull request hasn't had any new commits for approximately 4 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then. In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary. If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock. If you believe I commented on this pull request incorrectly, please report this here. |
|
I'm going to close this pull request as per my previous message. If you think what is being added/fixed here is still important, please remember to open an issue to keep track of it. Thanks! If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here. |
Description
This pull request is to address to split pull request #17844 , and it ensure compliance of astropy/coordinates Ruff rule unused-loop-control-variable (B007)
Fixes partially #14818