-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: Flake8 E741 #22913
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
CLN: Flake8 E741 #22913
Conversation
Hello @alimcmaster1! Thanks for submitting the PR.
|
from pandas import compat | ||
from pandas._libs import lib, algos as libalgos | ||
from pandas.compat import PY36 | ||
from pandas.compat import (range, map, zip, lrange, lmap, lzip, StringIO, u, |
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.
Combine with previous
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.
Thanks done!
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 is great, thanks, I know its nitpicky. For future reference in case you want to really match my habits, I usually put a newline after the compat imports, then collect core.dtypes imports in a section above the rest of core (lots of stuff depends on core.dtypes, but it depends on very little except for compat and _libs)
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.
Thanks much appreciated, I will update! I might add some kind of description to the contributing guide on the import layout you have described here, unless its already documented somewhere?
import pandas.io.formats.format as fmt | ||
import pandas.plotting._core as gfx | ||
from pandas import compat | ||
from pandas._libs import lib, algos as libalgos |
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.
Internal convention is to group by dependency structure. This usually means libs first, then util, compat, then core, then ...
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.
Actually the pytables module is a pretty good example
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.
Cool thanks for the example @jbrockmendel will fix this up!
pandas/core/frame.py
Outdated
|
||
from pandas.core.config import get_option | ||
# pylint: disable=E1101,E1103 | ||
# pylint: disable=W0212,W0231,W0703,W0622 |
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.
Any idea what these are and if they’re still needed?
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.
Good point I removed E1103,W0231 as they are no longer required:
"E1101: frame.py:2577:40: E1101: Module 'pandas.core.common' has no '_unpickle_array' member (no-member)"
"W0622: frame.py:36:0: W0622: Redefining built-in 'zip' (redefined-builtin)"
I guess we should really import like so: from pandas.compat import range as compatrange
?
Thanks for taking a look @datapythonista updated as per your comments. ln -> length is clearer to me too :) |
pandas/core/indexes/range.py
Outdated
@@ -512,33 +512,33 @@ def __getitem__(self, key): | |||
# This is basically PySlice_GetIndicesEx, but delegation to our | |||
# super routines if we don't have integers | |||
|
|||
l = len(self) | |||
length = len(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.
+1 good choice
pandas/core/indexing.py
Outdated
@@ -305,7 +305,7 @@ def _setitem_with_indexer(self, indexer, value): | |||
|
|||
# also has the side effect of consolidating in-place | |||
# TODO: Panel, DataFrame are not imported, remove? | |||
from pandas import Panel, DataFrame, Series # noqa | |||
from pandas import Series # noqa |
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.
I think the noqa
is now unnecessary
elif stop < 0: | ||
stop += l | ||
stop += target_len |
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.
+1 on all the changed names here; this is very clear
pandas/io/packers.py
Outdated
from pandas.core.sparse.api import SparseSeries, SparseDataFrame | ||
from pandas.core.sparse.array import BlockIndex, IntIndex | ||
from pandas.core.generic import NDFrame | ||
from pandas.errors import PerformanceWarning |
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.
pandas.errors is among the zero-dependency directories id put somewhere around util/compat
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.
Updated thanks!
pandas/io/pytables.py
Outdated
from pandas._libs import algos, lib, writers as libwriters | ||
from pandas._libs.tslibs import timezones | ||
|
||
from pandas.errors import PerformanceWarning | ||
from pandas import compat | ||
from pandas.compat import u_safe as u, PY3, range, lrange, string_types, 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.
u
is no longer needed, can be replaced by u
literal
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.
Replaced all occurrences with the literal for this file
In general, I'm in favor of sorting imports, but we shouldn't be doing manually and it should be linted, else we'll be doing it again in a few months. I'd recommend getting a consensus on an isort configuration that we all like, and then adding a lint check to ensure that the sort order is respected.
For dask-ml we use
|
Thanks @TomAugspurger totally agree, let me create an issue and see if we can decide on config set up. |
Codecov Report
@@ Coverage Diff @@
## master #22913 +/- ##
=========================================
Coverage ? 92.19%
=========================================
Files ? 169
Lines ? 50879
Branches ? 0
=========================================
Hits ? 46910
Misses ? 3969
Partials ? 0
Continue to review full report at Codecov.
|
Thanks @jbrockmendel for the review, ive updated as per your comments mind confirming this looks good? |
I think all my nitpickings have been addressed. |
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.
lgtm, great work.
It'd be nice at some point to get rid of the custom disables in the linting, but if that can be done, it should be in a separate PR
@@ -1,3 +1,5 @@ | |||
# pylint: disable=E1101 | |||
# pylint: disable=W0212,W0703,W0622 |
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.
i would rather not disable specific items for a whole file. Is there a reason for this?
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.
@jreback 100% agree, but these lines are already there in the original files, they've just been moved.
@alimcmaster1 removed some of the errors that were being ignored, but the ones left are not trivial.
Didn't check in detail, but E1101
is probably to avoid false positives in attributes that are created dynamically and not found in the linting. It's disabled like this in around 80 files, so it may be worth to move it to setup.cfg
and ignore it everywhere.
Didn't check the others, but I'd merge this PR as it is, and take care of all the pylint: disable
in a separate PR.
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.
ok that's fine.
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.
Thanks both, had a brief discussion above with @jbrockmendel about these.
"E1101: frame.py:2577:40: E1101: Module 'pandas.core.common' has no '_unpickle_array' member (no-member)" this is as @datapythonista described above.
"W0622: frame.py:36:0: W0622: Redefining built-in 'zip' (redefined-builtin)"
We should be able to get rid of W0622, I can do a follow up PR with this.
I will follow and remove E741 from our lint CI setup and fix this error for the few remaining test scripts.
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.
I'm merging #22863 as soon as the CI is green, so you may want to wait to remove E741, as it'll conflict.
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.
Merged. E741 should be removed from setup.cfg
and .pep8speaks.yml
. But not sure if the remaining tests are few. ;)
./pandas/tests/test_algos.py:375:9: E741 ambiguous variable name 'l'
./pandas/tests/test_multilevel.py:2065:9: E741 ambiguous variable name 'l'
./pandas/tests/frame/test_operators.py:796:9: E741 ambiguous variable name 'l'
./pandas/tests/frame/test_indexing.py:2079:9: E741 ambiguous variable name 'l'
./pandas/tests/frame/test_constructors.py:899:9: E741 ambiguous variable name 'l'
./pandas/tests/frame/test_constructors.py:926:9: E741 ambiguous variable name 'l'
./pandas/tests/frame/test_constructors.py:1747:9: E741 ambiguous variable name 'l'
./pandas/tests/frame/test_constructors.py:1752:9: E741 ambiguous variable name 'l'
./pandas/tests/plotting/common.py:260:24: E741 ambiguous variable name 'l'
./pandas/tests/plotting/test_frame.py:302:9: E741 ambiguous variable name 'l'
./pandas/tests/plotting/test_frame.py:310:9: E741 ambiguous variable name 'l'
./pandas/tests/plotting/test_datetimelike.py:545:9: E741 ambiguous variable name 'l'
./pandas/tests/plotting/test_datetimelike.py:560:9: E741 ambiguous variable name 'l'
./pandas/tests/plotting/test_datetimelike.py:575:9: E741 ambiguous variable name 'l'
./pandas/tests/plotting/test_datetimelike.py:595:9: E741 ambiguous variable name 'l'
./pandas/tests/plotting/test_datetimelike.py:611:9: E741 ambiguous variable name 'l'
./pandas/tests/plotting/test_datetimelike.py:642:9: E741 ambiguous variable name 'l'
./pandas/tests/plotting/test_datetimelike.py:953:17: E741 ambiguous variable name 'l'
./pandas/tests/plotting/test_datetimelike.py:966:17: E741 ambiguous variable name 'l'
./pandas/tests/plotting/test_datetimelike.py:984:17: E741 ambiguous variable name 'l'
./pandas/tests/plotting/test_datetimelike.py:998:17: E741 ambiguous variable name 'l'
./pandas/tests/indexing/test_loc.py:671:13: E741 ambiguous variable name 'l'
./pandas/tests/indexing/test_indexing.py:772:19: E741 ambiguous variable name 'l'
./pandas/tests/io/test_packers.py:515:9: E741 ambiguous variable name 'l'
./pandas/tests/io/test_packers.py:521:9: E741 ambiguous variable name 'l'
./pandas/tests/io/test_packers.py:529:9: E741 ambiguous variable name 'l'
./pandas/tests/io/test_pytables.py:2185:13: E741 ambiguous variable name 'l'
./pandas/tests/series/test_analytics.py:542:13: E741 ambiguous variable name 'l'
./pandas/tests/series/test_analytics.py:977:13: E741 ambiguous variable name 'l'
./pandas/tests/series/test_dtypes.py:246:9: E741 ambiguous variable name 'l'
./pandas/tests/series/test_dtypes.py:252:9: E741 ambiguous variable name 'l'
./pandas/tests/series/test_dtypes.py:273:9: E741 ambiguous variable name 'l'
@@ -1,10 +1,16 @@ | |||
# pylint: disable=W0223 |
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.
can you remove this warning? The general problem with these warnings is that they are added, but never removed.
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.
that's fine too
If you want to add checking for specific files for certain warnings, then add a line to lint.sh to do this. |
thanks @alimcmaster1 just want point out that we need a good way of validating import ordering before we wholesale fix it. |
thanks @jreback for the review. Ive raised an issue for this here #23048 , to clarify: by validating import ordering are you referring to the fact we need to group by dependency structure like @jbrockmendel is referring to here? Or am I missing something here? |
git diff upstream/master -u -- "*.py" | flake8 --diff
Import optimiser, makes things alphabetical and also removes unused eg,
Float64Index
, inpackers.py
. Do people prefer this or not?