Skip to content

Commit 21e8522

Browse files
alimcmaster1jreback
authored andcommitted
CLN: Flake8 E741 (#23131)
1 parent 85dc171 commit 21e8522

16 files changed

+102
-105
lines changed

.pep8speaks.yml

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pycodestyle:
1515
- E402, # module level import not at top of file
1616
- E722, # do not use bare except
1717
- E731, # do not assign a lambda expression, use a def
18-
- E741, # ambiguous variable name 'l'
1918
- C406, # Unnecessary list literal - rewrite as a dict literal.
2019
- C408, # Unnecessary dict call - rewrite as a literal.
2120
- C409 # Unnecessary list passed to tuple() - rewrite as a tuple literal.

pandas/tests/frame/test_constructors.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,7 @@ def empty_gen():
896896

897897
def test_constructor_list_of_lists(self):
898898
# GH #484
899-
l = [[1, 'a'], [2, 'b']]
900-
df = DataFrame(data=l, columns=["num", "str"])
899+
df = DataFrame(data=[[1, 'a'], [2, 'b']], columns=["num", "str"])
901900
assert is_integer_dtype(df['num'])
902901
assert df['str'].dtype == np.object_
903902

@@ -923,9 +922,9 @@ def __getitem__(self, n):
923922
def __len__(self, n):
924923
return self._lst.__len__()
925924

926-
l = [DummyContainer([1, 'a']), DummyContainer([2, 'b'])]
925+
lst_containers = [DummyContainer([1, 'a']), DummyContainer([2, 'b'])]
927926
columns = ["num", "str"]
928-
result = DataFrame(l, columns=columns)
927+
result = DataFrame(lst_containers, columns=columns)
929928
expected = DataFrame([[1, 'a'], [2, 'b']], columns=columns)
930929
tm.assert_frame_equal(result, expected, check_dtype=False)
931930

@@ -1744,14 +1743,14 @@ def test_constructor_categorical(self):
17441743

17451744
def test_constructor_categorical_series(self):
17461745

1747-
l = [1, 2, 3, 1]
1748-
exp = Series(l).astype('category')
1749-
res = Series(l, dtype='category')
1746+
items = [1, 2, 3, 1]
1747+
exp = Series(items).astype('category')
1748+
res = Series(items, dtype='category')
17501749
tm.assert_series_equal(res, exp)
17511750

1752-
l = ["a", "b", "c", "a"]
1753-
exp = Series(l).astype('category')
1754-
res = Series(l, dtype='category')
1751+
items = ["a", "b", "c", "a"]
1752+
exp = Series(items).astype('category')
1753+
res = Series(items, dtype='category')
17551754
tm.assert_series_equal(res, exp)
17561755

17571756
# insert into frame with different index

pandas/tests/frame/test_indexing.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2076,9 +2076,9 @@ def test_nested_exception(self):
20762076
# a named argument
20772077
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6],
20782078
"c": [7, 8, 9]}).set_index(["a", "b"])
2079-
l = list(df.index)
2080-
l[0] = ["a", "b"]
2081-
df.index = l
2079+
index = list(df.index)
2080+
index[0] = ["a", "b"]
2081+
df.index = index
20822082

20832083
try:
20842084
repr(df)

pandas/tests/frame/test_operators.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,8 @@ def test_boolean_comparison(self):
793793
b = np.array([2, 2])
794794
b_r = np.atleast_2d([2, 2])
795795
b_c = b_r.T
796-
l = (2, 2, 2)
797-
tup = tuple(l)
796+
lst = [2, 2, 2]
797+
tup = tuple(lst)
798798

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

807-
result = df > l
807+
result = df > lst
808808
assert_frame_equal(result, expected)
809809

810810
result = df > tup
@@ -827,7 +827,7 @@ def test_boolean_comparison(self):
827827
result = df == b
828828
assert_frame_equal(result, expected)
829829

830-
result = df == l
830+
result = df == lst
831831
assert_frame_equal(result, expected)
832832

833833
result = df == tup
@@ -850,7 +850,7 @@ def test_boolean_comparison(self):
850850
expected.index = df.index
851851
expected.columns = df.columns
852852

853-
result = df == l
853+
result = df == lst
854854
assert_frame_equal(result, expected)
855855

856856
result = df == tup

pandas/tests/indexing/test_indexing.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -768,34 +768,34 @@ def test_rhs_alignment(self):
768768
# assigned to. covers both uniform data-type & multi-type cases
769769
def run_tests(df, rhs, right):
770770
# label, index, slice
771-
r, i, s = list('bcd'), [1, 2, 3], slice(1, 4)
772-
c, j, l = ['joe', 'jolie'], [1, 2], slice(1, 3)
771+
lbl_one, idx_one, slice_one = list('bcd'), [1, 2, 3], slice(1, 4)
772+
lbl_two, idx_two, slice_two = ['joe', 'jolie'], [1, 2], slice(1, 3)
773773

774774
left = df.copy()
775-
left.loc[r, c] = rhs
775+
left.loc[lbl_one, lbl_two] = rhs
776776
tm.assert_frame_equal(left, right)
777777

778778
left = df.copy()
779-
left.iloc[i, j] = rhs
779+
left.iloc[idx_one, idx_two] = rhs
780780
tm.assert_frame_equal(left, right)
781781

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

789789
left = df.copy()
790790
with catch_warnings(record=True):
791791
simplefilter("ignore")
792-
left.ix[i, j] = rhs
792+
left.ix[idx_one, idx_two] = rhs
793793
tm.assert_frame_equal(left, right)
794794

795795
left = df.copy()
796796
with catch_warnings(record=True):
797797
simplefilter("ignore")
798-
left.ix[r, c] = rhs
798+
left.ix[lbl_one, lbl_two] = rhs
799799
tm.assert_frame_equal(left, right)
800800

801801
xs = np.arange(20).reshape(5, 4)

pandas/tests/indexing/test_loc.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,10 @@ def gen_test(l, l2):
668668
index=[0] * l2, columns=columns)])
669669

670670
def gen_expected(df, mask):
671-
l = len(mask)
671+
len_mask = len(mask)
672672
return pd.concat([df.take([0]),
673-
DataFrame(np.ones((l, len(columns))),
674-
index=[0] * l,
673+
DataFrame(np.ones((len_mask, len(columns))),
674+
index=[0] * len_mask,
675675
columns=columns),
676676
df.take(mask[1:])])
677677

pandas/tests/io/test_packers.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -512,27 +512,27 @@ def test_multi(self):
512512
for k in self.frame.keys():
513513
assert_frame_equal(self.frame[k], i_rec[k])
514514

515-
l = tuple([self.frame['float'], self.frame['float'].A,
516-
self.frame['float'].B, None])
517-
l_rec = self.encode_decode(l)
518-
check_arbitrary(l, l_rec)
515+
packed_items = tuple([self.frame['float'], self.frame['float'].A,
516+
self.frame['float'].B, None])
517+
l_rec = self.encode_decode(packed_items)
518+
check_arbitrary(packed_items, l_rec)
519519

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

527527
def test_iterator(self):
528528

529-
l = [self.frame['float'], self.frame['float']
530-
.A, self.frame['float'].B, None]
529+
packed_items = [self.frame['float'], self.frame['float'].A,
530+
self.frame['float'].B, None]
531531

532532
with ensure_clean(self.path) as path:
533-
to_msgpack(path, *l)
533+
to_msgpack(path, *packed_items)
534534
for i, packed in enumerate(read_msgpack(path, iterator=True)):
535-
check_arbitrary(packed, l[i])
535+
check_arbitrary(packed, packed_items[i])
536536

537537
def tests_datetimeindex_freq_issue(self):
538538

pandas/tests/io/test_pytables.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2182,14 +2182,14 @@ def test_unimplemented_dtypes_table_columns(self):
21822182

21832183
with ensure_clean_store(self.path) as store:
21842184

2185-
l = [('date', datetime.date(2001, 1, 2))]
2185+
dtypes = [('date', datetime.date(2001, 1, 2))]
21862186

21872187
# py3 ok for unicode
21882188
if not compat.PY3:
2189-
l.append(('unicode', u('\\u03c3')))
2189+
dtypes.append(('unicode', u('\\u03c3')))
21902190

21912191
# currently not supported dtypes ####
2192-
for n, f in l:
2192+
for n, f in dtypes:
21932193
df = tm.makeDataFrame()
21942194
df[n] = f
21952195
pytest.raises(

pandas/tests/plotting/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ def _check_text_labels(self, texts, expected):
256256
else:
257257
labels = [t.get_text() for t in texts]
258258
assert len(labels) == len(expected)
259-
for l, e in zip(labels, expected):
260-
assert l == e
259+
for label, e in zip(labels, expected):
260+
assert label == e
261261

262262
def _check_ticks_props(self, axes, xlabelsize=None, xrot=None,
263263
ylabelsize=None, yrot=None):

pandas/tests/plotting/test_datetimelike.py

+28-28
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,8 @@ def test_gaps(self):
542542
ts.plot(ax=ax)
543543
lines = ax.get_lines()
544544
assert len(lines) == 1
545-
l = lines[0]
546-
data = l.get_xydata()
545+
line = lines[0]
546+
data = line.get_xydata()
547547
assert isinstance(data, np.ma.core.MaskedArray)
548548
mask = data.mask
549549
assert mask[5:25, 1].all()
@@ -557,8 +557,8 @@ def test_gaps(self):
557557
ax = ts.plot(ax=ax)
558558
lines = ax.get_lines()
559559
assert len(lines) == 1
560-
l = lines[0]
561-
data = l.get_xydata()
560+
line = lines[0]
561+
data = line.get_xydata()
562562
assert isinstance(data, np.ma.core.MaskedArray)
563563
mask = data.mask
564564
assert mask[2:5, 1].all()
@@ -572,8 +572,8 @@ def test_gaps(self):
572572
ser.plot(ax=ax)
573573
lines = ax.get_lines()
574574
assert len(lines) == 1
575-
l = lines[0]
576-
data = l.get_xydata()
575+
line = lines[0]
576+
data = line.get_xydata()
577577
assert isinstance(data, np.ma.core.MaskedArray)
578578
mask = data.mask
579579
assert mask[2:5, 1].all()
@@ -592,8 +592,8 @@ def test_gap_upsample(self):
592592
lines = ax.get_lines()
593593
assert len(lines) == 1
594594
assert len(ax.right_ax.get_lines()) == 1
595-
l = lines[0]
596-
data = l.get_xydata()
595+
line = lines[0]
596+
data = line.get_xydata()
597597

598598
assert isinstance(data, np.ma.core.MaskedArray)
599599
mask = data.mask
@@ -608,8 +608,8 @@ def test_secondary_y(self):
608608
assert hasattr(ax, 'left_ax')
609609
assert not hasattr(ax, 'right_ax')
610610
axes = fig.get_axes()
611-
l = ax.get_lines()[0]
612-
xp = Series(l.get_ydata(), l.get_xdata())
611+
line = ax.get_lines()[0]
612+
xp = Series(line.get_ydata(), line.get_xdata())
613613
assert_series_equal(ser, xp)
614614
assert ax.get_yaxis().get_ticks_position() == 'right'
615615
assert not axes[0].get_yaxis().get_visible()
@@ -639,8 +639,8 @@ def test_secondary_y_ts(self):
639639
assert hasattr(ax, 'left_ax')
640640
assert not hasattr(ax, 'right_ax')
641641
axes = fig.get_axes()
642-
l = ax.get_lines()[0]
643-
xp = Series(l.get_ydata(), l.get_xdata()).to_timestamp()
642+
line = ax.get_lines()[0]
643+
xp = Series(line.get_ydata(), line.get_xdata()).to_timestamp()
644644
assert_series_equal(ser, xp)
645645
assert ax.get_yaxis().get_ticks_position() == 'right'
646646
assert not axes[0].get_yaxis().get_visible()
@@ -950,25 +950,25 @@ def test_from_resampling_area_line_mixed(self):
950950
dtype=np.float64)
951951
expected_y = np.zeros(len(expected_x), dtype=np.float64)
952952
for i in range(3):
953-
l = ax.lines[i]
954-
assert PeriodIndex(l.get_xdata()).freq == idxh.freq
955-
tm.assert_numpy_array_equal(l.get_xdata(orig=False),
953+
line = ax.lines[i]
954+
assert PeriodIndex(line.get_xdata()).freq == idxh.freq
955+
tm.assert_numpy_array_equal(line.get_xdata(orig=False),
956956
expected_x)
957957
# check stacked values are correct
958958
expected_y += low[i].values
959-
tm.assert_numpy_array_equal(l.get_ydata(orig=False),
959+
tm.assert_numpy_array_equal(line.get_ydata(orig=False),
960960
expected_y)
961961

962962
# check high dataframe result
963963
expected_x = idxh.to_period().asi8.astype(np.float64)
964964
expected_y = np.zeros(len(expected_x), dtype=np.float64)
965965
for i in range(3):
966-
l = ax.lines[3 + i]
967-
assert PeriodIndex(data=l.get_xdata()).freq == idxh.freq
968-
tm.assert_numpy_array_equal(l.get_xdata(orig=False),
966+
line = ax.lines[3 + i]
967+
assert PeriodIndex(data=line.get_xdata()).freq == idxh.freq
968+
tm.assert_numpy_array_equal(line.get_xdata(orig=False),
969969
expected_x)
970970
expected_y += high[i].values
971-
tm.assert_numpy_array_equal(l.get_ydata(orig=False),
971+
tm.assert_numpy_array_equal(line.get_ydata(orig=False),
972972
expected_y)
973973

974974
# high to low
@@ -981,12 +981,12 @@ def test_from_resampling_area_line_mixed(self):
981981
expected_x = idxh.to_period().asi8.astype(np.float64)
982982
expected_y = np.zeros(len(expected_x), dtype=np.float64)
983983
for i in range(3):
984-
l = ax.lines[i]
985-
assert PeriodIndex(data=l.get_xdata()).freq == idxh.freq
986-
tm.assert_numpy_array_equal(l.get_xdata(orig=False),
984+
line = ax.lines[i]
985+
assert PeriodIndex(data=line.get_xdata()).freq == idxh.freq
986+
tm.assert_numpy_array_equal(line.get_xdata(orig=False),
987987
expected_x)
988988
expected_y += high[i].values
989-
tm.assert_numpy_array_equal(l.get_ydata(orig=False),
989+
tm.assert_numpy_array_equal(line.get_ydata(orig=False),
990990
expected_y)
991991

992992
# check low dataframe result
@@ -995,12 +995,12 @@ def test_from_resampling_area_line_mixed(self):
995995
dtype=np.float64)
996996
expected_y = np.zeros(len(expected_x), dtype=np.float64)
997997
for i in range(3):
998-
l = ax.lines[3 + i]
999-
assert PeriodIndex(data=l.get_xdata()).freq == idxh.freq
1000-
tm.assert_numpy_array_equal(l.get_xdata(orig=False),
998+
lines = ax.lines[3 + i]
999+
assert PeriodIndex(data=lines.get_xdata()).freq == idxh.freq
1000+
tm.assert_numpy_array_equal(lines.get_xdata(orig=False),
10011001
expected_x)
10021002
expected_y += low[i].values
1003-
tm.assert_numpy_array_equal(l.get_ydata(orig=False),
1003+
tm.assert_numpy_array_equal(lines.get_ydata(orig=False),
10041004
expected_y)
10051005

10061006
@pytest.mark.slow

pandas/tests/plotting/test_frame.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,16 @@ def test_unsorted_index(self):
299299
df = DataFrame({'y': np.arange(100)}, index=np.arange(99, -1, -1),
300300
dtype=np.int64)
301301
ax = df.plot()
302-
l = ax.get_lines()[0]
303-
rs = l.get_xydata()
302+
lines = ax.get_lines()[0]
303+
rs = lines.get_xydata()
304304
rs = Series(rs[:, 1], rs[:, 0], dtype=np.int64, name='y')
305305
tm.assert_series_equal(rs, df.y, check_index_type=False)
306306
tm.close()
307307

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

0 commit comments

Comments
 (0)