Skip to content

CLN: Flake8 E741 #23131

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

Merged
merged 3 commits into from
Oct 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pep8speaks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pycodestyle:
- E402, # module level import not at top of file
- E722, # do not use bare except
- E731, # do not assign a lambda expression, use a def
- E741, # ambiguous variable name 'l'
- C406, # Unnecessary list literal - rewrite as a dict literal.
- C408, # Unnecessary dict call - rewrite as a literal.
- C409 # Unnecessary list passed to tuple() - rewrite as a tuple literal.
19 changes: 9 additions & 10 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,8 +896,7 @@ def empty_gen():

def test_constructor_list_of_lists(self):
# GH #484
l = [[1, 'a'], [2, 'b']]
df = DataFrame(data=l, columns=["num", "str"])
df = DataFrame(data=[[1, 'a'], [2, 'b']], columns=["num", "str"])
assert is_integer_dtype(df['num'])
assert df['str'].dtype == np.object_

Expand All @@ -923,9 +922,9 @@ def __getitem__(self, n):
def __len__(self, n):
return self._lst.__len__()

l = [DummyContainer([1, 'a']), DummyContainer([2, 'b'])]
lst_containers = [DummyContainer([1, 'a']), DummyContainer([2, 'b'])]
columns = ["num", "str"]
result = DataFrame(l, columns=columns)
result = DataFrame(lst_containers, columns=columns)
expected = DataFrame([[1, 'a'], [2, 'b']], columns=columns)
tm.assert_frame_equal(result, expected, check_dtype=False)

Expand Down Expand Up @@ -1744,14 +1743,14 @@ def test_constructor_categorical(self):

def test_constructor_categorical_series(self):

l = [1, 2, 3, 1]
exp = Series(l).astype('category')
res = Series(l, dtype='category')
items = [1, 2, 3, 1]
exp = Series(items).astype('category')
res = Series(items, dtype='category')
tm.assert_series_equal(res, exp)

l = ["a", "b", "c", "a"]
exp = Series(l).astype('category')
res = Series(l, dtype='category')
items = ["a", "b", "c", "a"]
exp = Series(items).astype('category')
res = Series(items, dtype='category')
tm.assert_series_equal(res, exp)

# insert into frame with different index
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/frame/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2076,9 +2076,9 @@ def test_nested_exception(self):
# a named argument
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6],
"c": [7, 8, 9]}).set_index(["a", "b"])
l = list(df.index)
l[0] = ["a", "b"]
df.index = l
index = list(df.index)
index[0] = ["a", "b"]
df.index = index

try:
repr(df)
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/frame/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,8 @@ def test_boolean_comparison(self):
b = np.array([2, 2])
b_r = np.atleast_2d([2, 2])
b_c = b_r.T
l = (2, 2, 2)
tup = tuple(l)
lst = [2, 2, 2]
tup = tuple(lst)

# gt
expected = DataFrame([[False, False], [False, True], [True, True]])
Expand All @@ -804,7 +804,7 @@ def test_boolean_comparison(self):
result = df.values > b
assert_numpy_array_equal(result, expected.values)

result = df > l
result = df > lst
assert_frame_equal(result, expected)

result = df > tup
Expand All @@ -827,7 +827,7 @@ def test_boolean_comparison(self):
result = df == b
assert_frame_equal(result, expected)

result = df == l
result = df == lst
assert_frame_equal(result, expected)

result = df == tup
Expand All @@ -850,7 +850,7 @@ def test_boolean_comparison(self):
expected.index = df.index
expected.columns = df.columns

result = df == l
result = df == lst
assert_frame_equal(result, expected)

result = df == tup
Expand Down
14 changes: 7 additions & 7 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,34 +768,34 @@ def test_rhs_alignment(self):
# assigned to. covers both uniform data-type & multi-type cases
def run_tests(df, rhs, right):
# label, index, slice
r, i, s = list('bcd'), [1, 2, 3], slice(1, 4)
c, j, l = ['joe', 'jolie'], [1, 2], slice(1, 3)
lbl_one, idx_one, slice_one = list('bcd'), [1, 2, 3], slice(1, 4)
lbl_two, idx_two, slice_two = ['joe', 'jolie'], [1, 2], slice(1, 3)

left = df.copy()
left.loc[r, c] = rhs
left.loc[lbl_one, lbl_two] = rhs
tm.assert_frame_equal(left, right)

left = df.copy()
left.iloc[i, j] = rhs
left.iloc[idx_one, idx_two] = rhs
tm.assert_frame_equal(left, right)

left = df.copy()
with catch_warnings(record=True):
# XXX: finer-filter here.
simplefilter("ignore")
left.ix[s, l] = rhs
left.ix[slice_one, slice_two] = rhs
tm.assert_frame_equal(left, right)

left = df.copy()
with catch_warnings(record=True):
simplefilter("ignore")
left.ix[i, j] = rhs
left.ix[idx_one, idx_two] = rhs
tm.assert_frame_equal(left, right)

left = df.copy()
with catch_warnings(record=True):
simplefilter("ignore")
left.ix[r, c] = rhs
left.ix[lbl_one, lbl_two] = rhs
tm.assert_frame_equal(left, right)

xs = np.arange(20).reshape(5, 4)
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,10 @@ def gen_test(l, l2):
index=[0] * l2, columns=columns)])

def gen_expected(df, mask):
l = len(mask)
len_mask = len(mask)
return pd.concat([df.take([0]),
DataFrame(np.ones((l, len(columns))),
index=[0] * l,
DataFrame(np.ones((len_mask, len(columns))),
index=[0] * len_mask,
columns=columns),
df.take(mask[1:])])

Expand Down
24 changes: 12 additions & 12 deletions pandas/tests/io/test_packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,27 +512,27 @@ def test_multi(self):
for k in self.frame.keys():
assert_frame_equal(self.frame[k], i_rec[k])

l = tuple([self.frame['float'], self.frame['float'].A,
self.frame['float'].B, None])
l_rec = self.encode_decode(l)
check_arbitrary(l, l_rec)
packed_items = tuple([self.frame['float'], self.frame['float'].A,
self.frame['float'].B, None])
l_rec = self.encode_decode(packed_items)
check_arbitrary(packed_items, l_rec)

# this is an oddity in that packed lists will be returned as tuples
l = [self.frame['float'], self.frame['float']
.A, self.frame['float'].B, None]
l_rec = self.encode_decode(l)
packed_items = [self.frame['float'], self.frame['float'].A,
self.frame['float'].B, None]
l_rec = self.encode_decode(packed_items)
assert isinstance(l_rec, tuple)
check_arbitrary(l, l_rec)
check_arbitrary(packed_items, l_rec)

def test_iterator(self):

l = [self.frame['float'], self.frame['float']
.A, self.frame['float'].B, None]
packed_items = [self.frame['float'], self.frame['float'].A,
self.frame['float'].B, None]

with ensure_clean(self.path) as path:
to_msgpack(path, *l)
to_msgpack(path, *packed_items)
for i, packed in enumerate(read_msgpack(path, iterator=True)):
check_arbitrary(packed, l[i])
check_arbitrary(packed, packed_items[i])

def tests_datetimeindex_freq_issue(self):

Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/io/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2182,14 +2182,14 @@ def test_unimplemented_dtypes_table_columns(self):

with ensure_clean_store(self.path) as store:

l = [('date', datetime.date(2001, 1, 2))]
dtypes = [('date', datetime.date(2001, 1, 2))]

# py3 ok for unicode
if not compat.PY3:
l.append(('unicode', u('\\u03c3')))
dtypes.append(('unicode', u('\\u03c3')))

# currently not supported dtypes ####
for n, f in l:
for n, f in dtypes:
df = tm.makeDataFrame()
df[n] = f
pytest.raises(
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/plotting/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ def _check_text_labels(self, texts, expected):
else:
labels = [t.get_text() for t in texts]
assert len(labels) == len(expected)
for l, e in zip(labels, expected):
assert l == e
for label, e in zip(labels, expected):
assert label == e

def _check_ticks_props(self, axes, xlabelsize=None, xrot=None,
ylabelsize=None, yrot=None):
Expand Down
56 changes: 28 additions & 28 deletions pandas/tests/plotting/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ def test_gaps(self):
ts.plot(ax=ax)
lines = ax.get_lines()
assert len(lines) == 1
l = lines[0]
data = l.get_xydata()
line = lines[0]
data = line.get_xydata()
assert isinstance(data, np.ma.core.MaskedArray)
mask = data.mask
assert mask[5:25, 1].all()
Expand All @@ -557,8 +557,8 @@ def test_gaps(self):
ax = ts.plot(ax=ax)
lines = ax.get_lines()
assert len(lines) == 1
l = lines[0]
data = l.get_xydata()
line = lines[0]
data = line.get_xydata()
assert isinstance(data, np.ma.core.MaskedArray)
mask = data.mask
assert mask[2:5, 1].all()
Expand All @@ -572,8 +572,8 @@ def test_gaps(self):
ser.plot(ax=ax)
lines = ax.get_lines()
assert len(lines) == 1
l = lines[0]
data = l.get_xydata()
line = lines[0]
data = line.get_xydata()
assert isinstance(data, np.ma.core.MaskedArray)
mask = data.mask
assert mask[2:5, 1].all()
Expand All @@ -592,8 +592,8 @@ def test_gap_upsample(self):
lines = ax.get_lines()
assert len(lines) == 1
assert len(ax.right_ax.get_lines()) == 1
l = lines[0]
data = l.get_xydata()
line = lines[0]
data = line.get_xydata()

assert isinstance(data, np.ma.core.MaskedArray)
mask = data.mask
Expand All @@ -608,8 +608,8 @@ def test_secondary_y(self):
assert hasattr(ax, 'left_ax')
assert not hasattr(ax, 'right_ax')
axes = fig.get_axes()
l = ax.get_lines()[0]
xp = Series(l.get_ydata(), l.get_xdata())
line = ax.get_lines()[0]
xp = Series(line.get_ydata(), line.get_xdata())
assert_series_equal(ser, xp)
assert ax.get_yaxis().get_ticks_position() == 'right'
assert not axes[0].get_yaxis().get_visible()
Expand Down Expand Up @@ -639,8 +639,8 @@ def test_secondary_y_ts(self):
assert hasattr(ax, 'left_ax')
assert not hasattr(ax, 'right_ax')
axes = fig.get_axes()
l = ax.get_lines()[0]
xp = Series(l.get_ydata(), l.get_xdata()).to_timestamp()
line = ax.get_lines()[0]
xp = Series(line.get_ydata(), line.get_xdata()).to_timestamp()
assert_series_equal(ser, xp)
assert ax.get_yaxis().get_ticks_position() == 'right'
assert not axes[0].get_yaxis().get_visible()
Expand Down Expand Up @@ -950,25 +950,25 @@ def test_from_resampling_area_line_mixed(self):
dtype=np.float64)
expected_y = np.zeros(len(expected_x), dtype=np.float64)
for i in range(3):
l = ax.lines[i]
assert PeriodIndex(l.get_xdata()).freq == idxh.freq
tm.assert_numpy_array_equal(l.get_xdata(orig=False),
line = ax.lines[i]
assert PeriodIndex(line.get_xdata()).freq == idxh.freq
tm.assert_numpy_array_equal(line.get_xdata(orig=False),
expected_x)
# check stacked values are correct
expected_y += low[i].values
tm.assert_numpy_array_equal(l.get_ydata(orig=False),
tm.assert_numpy_array_equal(line.get_ydata(orig=False),
expected_y)

# check high dataframe result
expected_x = idxh.to_period().asi8.astype(np.float64)
expected_y = np.zeros(len(expected_x), dtype=np.float64)
for i in range(3):
l = ax.lines[3 + i]
assert PeriodIndex(data=l.get_xdata()).freq == idxh.freq
tm.assert_numpy_array_equal(l.get_xdata(orig=False),
line = ax.lines[3 + i]
assert PeriodIndex(data=line.get_xdata()).freq == idxh.freq
tm.assert_numpy_array_equal(line.get_xdata(orig=False),
expected_x)
expected_y += high[i].values
tm.assert_numpy_array_equal(l.get_ydata(orig=False),
tm.assert_numpy_array_equal(line.get_ydata(orig=False),
expected_y)

# high to low
Expand All @@ -981,12 +981,12 @@ def test_from_resampling_area_line_mixed(self):
expected_x = idxh.to_period().asi8.astype(np.float64)
expected_y = np.zeros(len(expected_x), dtype=np.float64)
for i in range(3):
l = ax.lines[i]
assert PeriodIndex(data=l.get_xdata()).freq == idxh.freq
tm.assert_numpy_array_equal(l.get_xdata(orig=False),
line = ax.lines[i]
assert PeriodIndex(data=line.get_xdata()).freq == idxh.freq
tm.assert_numpy_array_equal(line.get_xdata(orig=False),
expected_x)
expected_y += high[i].values
tm.assert_numpy_array_equal(l.get_ydata(orig=False),
tm.assert_numpy_array_equal(line.get_ydata(orig=False),
expected_y)

# check low dataframe result
Expand All @@ -995,12 +995,12 @@ def test_from_resampling_area_line_mixed(self):
dtype=np.float64)
expected_y = np.zeros(len(expected_x), dtype=np.float64)
for i in range(3):
l = ax.lines[3 + i]
assert PeriodIndex(data=l.get_xdata()).freq == idxh.freq
tm.assert_numpy_array_equal(l.get_xdata(orig=False),
lines = ax.lines[3 + i]
assert PeriodIndex(data=lines.get_xdata()).freq == idxh.freq
tm.assert_numpy_array_equal(lines.get_xdata(orig=False),
expected_x)
expected_y += low[i].values
tm.assert_numpy_array_equal(l.get_ydata(orig=False),
tm.assert_numpy_array_equal(lines.get_ydata(orig=False),
expected_y)

@pytest.mark.slow
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/plotting/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,16 @@ def test_unsorted_index(self):
df = DataFrame({'y': np.arange(100)}, index=np.arange(99, -1, -1),
dtype=np.int64)
ax = df.plot()
l = ax.get_lines()[0]
rs = l.get_xydata()
lines = ax.get_lines()[0]
rs = lines.get_xydata()
rs = Series(rs[:, 1], rs[:, 0], dtype=np.int64, name='y')
tm.assert_series_equal(rs, df.y, check_index_type=False)
tm.close()

df.index = pd.Index(np.arange(99, -1, -1), dtype=np.float64)
ax = df.plot()
l = ax.get_lines()[0]
rs = l.get_xydata()
lines = ax.get_lines()[0]
rs = lines.get_xydata()
rs = Series(rs[:, 1], rs[:, 0], dtype=np.int64, name='y')
tm.assert_series_equal(rs, df.y)

Expand Down
Loading