Skip to content

CI: fix flake C413, C414, C416 errors #29646

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 4 commits into from
Nov 16, 2019
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
hooks:
- id: flake8
language: python_venv
additional_dependencies: [flake8-comprehensions]
additional_dependencies: [flake8-comprehensions>=3.1.0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should also change in environment.yaml

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jreback done.

- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.20
hooks:
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/categoricals.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def setup(self, dtype):
np.random.seed(1234)
n = 5 * 10 ** 5
sample_size = 100
arr = [i for i in np.random.randint(0, n // 10, size=n)]
arr = list(np.random.randint(0, n // 10, size=n))
if dtype == "object":
arr = [f"s{i:04d}" for i in arr]
self.sample = np.random.choice(arr, sample_size)
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/frame_ctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class FromLists:
def setup(self):
N = 1000
M = 100
self.data = [[j for j in range(M)] for i in range(N)]
self.data = [list(range(M)) for i in range(N)]

def time_frame_from_lists(self):
self.df = DataFrame(self.data)
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ Example:

mi = pd.MultiIndex.from_product([list('AB'), list('CD'), list('EF')],
names=['AB', 'CD', 'EF'])
df = pd.DataFrame([i for i in range(len(mi))], index=mi, columns=['N'])
df = pd.DataFrame(list(range(len(mi))), index=mi, columns=['N'])
df
df.rename_axis(index={'CD': 'New'})

Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
- black<=19.3b0
- cpplint
- flake8
- flake8-comprehensions # used by flake8, linting of unnecessary comprehensions
- flake8-comprehensions>=3.1.0 # used by flake8, linting of unnecessary comprehensions
- flake8-rst>=0.6.0,<=0.7.0 # linting of code blocks in rst files
- isort # check that imports are in the right order
- mypy=0.720
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ def remove_categories(self, removals, inplace=False):
if not is_list_like(removals):
removals = [removals]

removal_set = set(list(removals))
removal_set = set(removals)
not_included = removal_set - set(self.dtype.categories)
new_categories = [c for c in self.dtype.categories if c not in removal_set]

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/sparse/scipy_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _get_label_to_i_dict(labels, sort_labels=False):
"""
labels = Index(map(tuple, labels)).unique().tolist() # squish
if sort_labels:
labels = sorted(list(labels))
labels = sorted(labels)
d = OrderedDict((k, i) for i, k in enumerate(labels))
return d

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4281,7 +4281,7 @@ def set_index(
arrays = []
names = []
if append:
names = [x for x in self.index.names]
names = list(self.index.names)
if isinstance(self.index, ABCMultiIndex):
for i in range(self.index.nlevels):
arrays.append(self.index._get_level_values(i))
Expand Down Expand Up @@ -7268,7 +7268,7 @@ def _series_round(s, decimals):
if isinstance(decimals, Series):
if not decimals.index.is_unique:
raise ValueError("Index of decimals must be unique")
new_cols = [col for col in _dict_round(self, decimals)]
new_cols = list(_dict_round(self, decimals))
elif is_integer(decimals):
# Dispatch to Series.round
new_cols = [_series_round(v, decimals) for _, v in self.items()]
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def _verify_integrity(self, codes=None, levels=None):
if not level.is_unique:
raise ValueError(
"Level values must be unique: {values} on "
"level {level}".format(values=[value for value in level], level=i)
"level {level}".format(values=list(level), level=i)
)
if self.sortorder is not None:
if self.sortorder > self._lexsort_depth():
Expand Down Expand Up @@ -1992,8 +1992,8 @@ def levshape(self):
def __reduce__(self):
"""Necessary for making this object picklable"""
d = dict(
levels=[lev for lev in self.levels],
codes=[level_codes for level_codes in self.codes],
levels=list(self.levels),
codes=list(self.codes),
sortorder=self.sortorder,
names=list(self.names),
)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def get_ftypes(self):
def __getstate__(self):
block_values = [b.values for b in self.blocks]
block_items = [self.items[b.mgr_locs.indexer] for b in self.blocks]
axes_array = [ax for ax in self.axes]
axes_array = list(self.axes)

extra_state = {
"0.14.1": {
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ def f(value):

# we require at least Ymd
required = ["year", "month", "day"]
req = sorted(list(set(required) - set(unit_rev.keys())))
req = sorted(set(required) - set(unit_rev.keys()))
if len(req):
raise ValueError(
"to assemble mappings requires at least that "
Expand All @@ -866,7 +866,7 @@ def f(value):
)

# keys we don't recognize
excess = sorted(list(set(unit_rev.keys()) - set(_unit_map.values())))
excess = sorted(set(unit_rev.keys()) - set(_unit_map.values()))
if len(excess):
raise ValueError(
"extra keys have been passed "
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ def ix(col):

# remove index items from content and columns, don't pop in
# loop
for i in reversed(sorted(to_remove)):
for i in sorted(to_remove, reverse=True):
data.pop(i)
if not self._implicit_index:
columns.pop(i)
Expand Down Expand Up @@ -1637,7 +1637,7 @@ def _get_name(icol):

# remove index items from content and columns, don't pop in
# loop
for c in reversed(sorted(to_remove)):
for c in sorted(to_remove, reverse=True):
data.pop(c)
col_names.remove(c)

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ def info(self) -> str:
type=type(self), path=pprint_thing(self._path)
)
if self.is_open:
lkeys = sorted(list(self.keys()))
lkeys = sorted(self.keys())
if len(lkeys):
keys = []
values = []
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def check(self, namespace, expected, ignored=None):

result = sorted(f for f in dir(namespace) if not f.startswith("__"))
if ignored is not None:
result = sorted(list(set(result) - set(ignored)))
result = sorted(set(result) - set(ignored))

expected = sorted(expected)
tm.assert_almost_equal(result, expected)
Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/frame/test_alter_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def test_set_index_custom_label_hashable_iterable(self):
class Thing(frozenset):
# need to stabilize repr for KeyError (due to random order in sets)
def __repr__(self) -> str:
tmp = sorted(list(self))
tmp = sorted(self)
# double curly brace prints one brace in format string
return "frozenset({{{}}})".format(", ".join(map(repr, tmp)))

Expand Down Expand Up @@ -745,8 +745,7 @@ def test_rename_axis_mapper(self):
# GH 19978
mi = MultiIndex.from_product([["a", "b", "c"], [1, 2]], names=["ll", "nn"])
df = DataFrame(
{"x": [i for i in range(len(mi))], "y": [i * 10 for i in range(len(mi))]},
index=mi,
{"x": list(range(len(mi))), "y": [i * 10 for i in range(len(mi))]}, index=mi
)

# Test for rename of the Index object of columns
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ def test_mode_dropna(self, dropna, expected):
}
)

result = df[sorted(list(expected.keys()))].mode(dropna=dropna)
result = df[sorted(expected.keys())].mode(dropna=dropna)
expected = DataFrame(expected)
tm.assert_frame_equal(result, expected)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def verify(df):
for i, j in zip(rows, cols):
left = sorted(df.iloc[i, j].split("."))
right = mk_list(df.index[i]) + mk_list(df.columns[j])
right = sorted(list(map(cast, right)))
right = sorted(map(cast, right))
assert left == right

df = DataFrame(
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/groupby/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -1300,8 +1300,8 @@ def test_size_groupby_all_null():
([np.nan, 4.0, np.nan, 2.0, np.nan], [np.nan, 4.0, np.nan, 2.0, np.nan]),
# Timestamps
(
[x for x in pd.date_range("1/1/18", freq="D", periods=5)],
[x for x in pd.date_range("1/1/18", freq="D", periods=5)][::-1],
list(pd.date_range("1/1/18", freq="D", periods=5)),
list(pd.date_range("1/1/18", freq="D", periods=5))[::-1],
),
# All NA
([np.nan] * 5, [np.nan] * 5),
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/indexes/timedeltas/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_union_bug_1730(self):
rng_b = timedelta_range("1 day", periods=4, freq="4H")

result = rng_a.union(rng_b)
exp = TimedeltaIndex(sorted(set(list(rng_a)) | set(list(rng_b))))
exp = TimedeltaIndex(sorted(set(rng_a) | set(rng_b)))
tm.assert_index_equal(result, exp)

def test_union_bug_1745(self):
Expand All @@ -50,7 +50,7 @@ def test_union_bug_1745(self):
)

result = left.union(right)
exp = TimedeltaIndex(sorted(set(list(left)) | set(list(right))))
exp = TimedeltaIndex(sorted(set(left) | set(right)))
tm.assert_index_equal(result, exp)

def test_union_bug_4564(self):
Expand All @@ -59,7 +59,7 @@ def test_union_bug_4564(self):
right = left + pd.offsets.Minute(15)

result = left.union(right)
exp = TimedeltaIndex(sorted(set(list(left)) | set(list(right))))
exp = TimedeltaIndex(sorted(set(left) | set(right)))
tm.assert_index_equal(result, exp)

def test_intersection_bug_1708(self):
Expand Down
10 changes: 2 additions & 8 deletions pandas/tests/indexing/multiindex/test_loc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import itertools

import numpy as np
import pytest

Expand Down Expand Up @@ -223,17 +221,13 @@ def test_loc_getitem_int_slice(self):
# GH 3053
# loc should treat integer slices like label slices

index = MultiIndex.from_tuples(
[t for t in itertools.product([6, 7, 8], ["a", "b"])]
)
index = MultiIndex.from_product([[6, 7, 8], ["a", "b"]])
df = DataFrame(np.random.randn(6, 6), index, index)
result = df.loc[6:8, :]
expected = df
tm.assert_frame_equal(result, expected)

index = MultiIndex.from_tuples(
[t for t in itertools.product([10, 20, 30], ["a", "b"])]
)
index = MultiIndex.from_product([[10, 20, 30], ["a", "b"]])
df = DataFrame(np.random.randn(6, 6), index, index)
result = df.loc[20:30, :]
expected = df.iloc[2:]
Expand Down
8 changes: 2 additions & 6 deletions pandas/tests/indexing/multiindex/test_xs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from itertools import product

import numpy as np
import pytest

Expand Down Expand Up @@ -159,10 +157,8 @@ def test_xs_setting_with_copy_error_multiple(four_level_index_dataframe):
def test_xs_integer_key():
# see gh-2107
dates = range(20111201, 20111205)
ids = "abcde"
index = MultiIndex.from_tuples(
[x for x in product(dates, ids)], names=["date", "secid"]
)
ids = list("abcde")
index = MultiIndex.from_product([dates, ids], names=["date", "secid"])
df = DataFrame(np.random.randn(len(index), 3), index, ["X", "Y", "Z"])

result = df.xs(20111201, level="date")
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexing/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def test_getitem_with_listlike(self):
[[1, 0], [0, 1]], dtype="uint8", index=[0, 1], columns=cats
)
dummies = pd.get_dummies(cats)
result = dummies[[c for c in dummies.columns]]
result = dummies[list(dummies.columns)]
tm.assert_frame_equal(result, expected)

def test_setitem_listlike(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/formats/test_to_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def test_css_to_excel_inherited(css, inherited, expected):
@pytest.mark.parametrize(
"input_color,output_color",
(
[(name, rgb) for name, rgb in CSSToExcelConverter.NAMED_COLORS.items()]
list(CSSToExcelConverter.NAMED_COLORS.items())
+ [("#" + rgb, rgb) for rgb in CSSToExcelConverter.NAMED_COLORS.values()]
+ [("#F0F", "FF00FF"), ("#ABC", "AABBCC")]
),
Expand Down
Loading