-
-
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
Changes from all commits
ed8fbbb
0779dfb
869ca05
9c72397
9474944
76c1f8f
04478f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# pylint: disable=E1101 | ||
# pylint: disable=W0212,W0703,W0622 | ||
""" | ||
DataFrame | ||
--------- | ||
|
@@ -9,11 +11,9 @@ | |
labeling information | ||
""" | ||
from __future__ import division | ||
# pylint: disable=E1101,E1103 | ||
# pylint: disable=W0212,W0231,W0703,W0622 | ||
|
||
import functools | ||
import collections | ||
import functools | ||
import itertools | ||
import sys | ||
import warnings | ||
|
@@ -22,7 +22,20 @@ | |
import numpy as np | ||
import numpy.ma as ma | ||
|
||
from pandas.core.accessor import CachedAccessor | ||
from pandas._libs import lib, algos as libalgos | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Cool thanks for the example @jbrockmendel will fix this up! |
||
|
||
from pandas.util._decorators import (Appender, Substitution, | ||
rewrite_axis_style_signature, | ||
deprecate_kwarg) | ||
from pandas.util._validators import (validate_bool_kwarg, | ||
validate_axis_style_args) | ||
|
||
from pandas import compat | ||
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 commentThe 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 commentThe 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 commentThe 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 commentThe 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? |
||
OrderedDict, PY36, raise_with_traceback, | ||
string_and_binary_types) | ||
from pandas.compat.numpy import function as nv | ||
|
||
from pandas.core.dtypes.cast import ( | ||
maybe_upcast, | ||
cast_scalar_to_array, | ||
|
@@ -62,46 +75,32 @@ | |
from pandas.core.dtypes.concat import _get_sliced_frame_result_type | ||
from pandas.core.dtypes.missing import isna, notna | ||
|
||
|
||
from pandas.core import algorithms | ||
from pandas.core import common as com | ||
from pandas.core import nanops | ||
from pandas.core import ops | ||
from pandas.core.accessor import CachedAccessor | ||
from pandas.core.arrays import Categorical, ExtensionArray | ||
from pandas.core.config import get_option | ||
from pandas.core.generic import NDFrame, _shared_docs | ||
from pandas.core.index import (Index, MultiIndex, ensure_index, | ||
ensure_index_from_sequences) | ||
from pandas.core.indexes import base as ibase | ||
from pandas.core.indexes.datetimes import DatetimeIndex | ||
from pandas.core.indexes.period import PeriodIndex | ||
from pandas.core.indexes.timedeltas import TimedeltaIndex | ||
from pandas.core.indexing import (maybe_droplevels, convert_to_index_sliceable, | ||
check_bool_indexer) | ||
from pandas.core.internals import (BlockManager, | ||
create_block_manager_from_arrays, | ||
create_block_manager_from_blocks) | ||
from pandas.core.series import Series | ||
from pandas.core.arrays import Categorical, ExtensionArray | ||
import pandas.core.algorithms as algorithms | ||
from pandas.compat import (range, map, zip, lrange, lmap, lzip, StringIO, u, | ||
OrderedDict, raise_with_traceback, | ||
string_and_binary_types) | ||
from pandas import compat | ||
from pandas.compat import PY36 | ||
from pandas.compat.numpy import function as nv | ||
from pandas.util._decorators import (Appender, Substitution, | ||
rewrite_axis_style_signature, | ||
deprecate_kwarg) | ||
from pandas.util._validators import (validate_bool_kwarg, | ||
validate_axis_style_args) | ||
|
||
from pandas.core.indexes.period import PeriodIndex | ||
from pandas.core.indexes.datetimes import DatetimeIndex | ||
from pandas.core.indexes.timedeltas import TimedeltaIndex | ||
import pandas.core.indexes.base as ibase | ||
|
||
import pandas.core.common as com | ||
import pandas.core.nanops as nanops | ||
import pandas.core.ops as ops | ||
import pandas.io.formats.console as console | ||
import pandas.io.formats.format as fmt | ||
from pandas.io.formats import console | ||
from pandas.io.formats import format as fmt | ||
from pandas.io.formats.printing import pprint_thing | ||
import pandas.plotting._core as gfx | ||
jbrockmendel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
from pandas._libs import lib, algos as libalgos | ||
|
||
from pandas.core.config import get_option | ||
import pandas.plotting._core as gfx | ||
|
||
# --------------------------------------------------------------------- | ||
# Docstring templates | ||
|
@@ -1003,7 +1002,7 @@ def dot(self, other): | |
rvals = np.asarray(other) | ||
if lvals.shape[1] != rvals.shape[0]: | ||
raise ValueError('Dot product shape mismatch, ' | ||
'{l} vs {r}'.format(l=lvals.shape, | ||
'{s} vs {r}'.format(s=lvals.shape, | ||
r=rvals.shape)) | ||
|
||
if isinstance(other, DataFrame): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
# pylint: disable=W0223 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. that's fine too |
||
import textwrap | ||
import warnings | ||
|
||
import numpy as np | ||
from pandas.compat import range, zip | ||
from pandas._libs.indexing import _NDFrameIndexerBase | ||
from pandas.util._decorators import Appender | ||
|
||
from pandas.errors import AbstractMethodError | ||
|
||
import pandas.compat as compat | ||
from pandas.core.dtypes.generic import ABCDataFrame, ABCPanel, ABCSeries | ||
from pandas.compat import range, zip | ||
|
||
from pandas.core.dtypes.common import ( | ||
is_integer_dtype, | ||
is_integer, is_float, | ||
|
@@ -14,14 +20,11 @@ | |
is_scalar, | ||
is_sparse, | ||
ensure_platform_int) | ||
from pandas.core.dtypes.generic import ABCDataFrame, ABCPanel, ABCSeries | ||
from pandas.core.dtypes.missing import isna, _infer_fill_value | ||
from pandas.errors import AbstractMethodError | ||
from pandas.util._decorators import Appender | ||
|
||
from pandas.core.index import Index, MultiIndex | ||
|
||
import pandas.core.common as com | ||
from pandas._libs.indexing import _NDFrameIndexerBase | ||
from pandas.core.index import Index, MultiIndex | ||
|
||
|
||
# the supported indexers | ||
|
@@ -304,8 +307,7 @@ def _setitem_with_indexer(self, indexer, value): | |
self._has_valid_setitem_indexer(indexer) | ||
|
||
# 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 | ||
info_axis = self.obj._info_axis_number | ||
|
||
# maybe partial set | ||
|
@@ -553,14 +555,14 @@ def can_do_equal_len(): | |
is_scalar(plane_indexer[0])): | ||
return False | ||
|
||
l = len(value) | ||
item = labels[0] | ||
index = self.obj[item].index | ||
|
||
values_len = len(value) | ||
# equal len list/ndarray | ||
if len(index) == l: | ||
if len(index) == values_len: | ||
return True | ||
elif lplane_indexer == l: | ||
elif lplane_indexer == values_len: | ||
return True | ||
|
||
return False | ||
|
@@ -717,8 +719,8 @@ def ravel(i): | |
|
||
# single indexer | ||
if len(indexer) > 1 and not multiindex_indexer: | ||
l = len(indexer[1]) | ||
ser = np.tile(ser, l).reshape(l, -1).T | ||
len_indexer = len(indexer[1]) | ||
ser = np.tile(ser, len_indexer).reshape(len_indexer, -1).T | ||
|
||
return ser | ||
|
||
|
@@ -2077,9 +2079,9 @@ def _validate_key(self, key, axis): | |
elif is_list_like_indexer(key): | ||
# check that the key does not exceed the maximum size of the index | ||
arr = np.array(key) | ||
l = len(self.obj._get_axis(axis)) | ||
len_axis = len(self.obj._get_axis(axis)) | ||
|
||
if len(arr) and (arr.max() >= l or arr.min() < -l): | ||
if len(arr) and (arr.max() >= len_axis or arr.min() < -len_axis): | ||
raise IndexError("positional indexers are out-of-bounds") | ||
else: | ||
raise ValueError("Can only index by location with " | ||
|
@@ -2136,9 +2138,8 @@ def _validate_integer(self, key, axis): | |
If 'key' is not a valid position in axis 'axis' | ||
""" | ||
|
||
ax = self.obj._get_axis(axis) | ||
l = len(ax) | ||
if key >= l or key < -l: | ||
len_axis = len(self.obj._get_axis(axis)) | ||
if key >= len_axis or key < -len_axis: | ||
raise IndexError("single positional indexer is out-of-bounds") | ||
|
||
def _getitem_tuple(self, tup): | ||
|
@@ -2425,18 +2426,18 @@ def length_of_indexer(indexer, target=None): | |
"""return the length of a single non-tuple indexer which could be a slice | ||
""" | ||
if target is not None and isinstance(indexer, slice): | ||
l = len(target) | ||
target_len = len(target) | ||
start = indexer.start | ||
stop = indexer.stop | ||
step = indexer.step | ||
if start is None: | ||
start = 0 | ||
elif start < 0: | ||
start += l | ||
if stop is None or stop > l: | ||
stop = l | ||
start += target_len | ||
if stop is None or stop > target_len: | ||
stop = target_len | ||
elif stop < 0: | ||
stop += l | ||
stop += target_len | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 on all the changed names here; this is very clear |
||
if step is None: | ||
step = 1 | ||
elif step < 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.
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 tosetup.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. ;)