diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f98273a336cf..3bed68fd8d2fc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: hooks: - id: flake8 language: python_venv - additional_dependencies: [flake8-comprehensions] + additional_dependencies: [flake8-comprehensions>=3.1.0] - repo: https://github.com/pre-commit/mirrors-isort rev: v4.3.20 hooks: diff --git a/asv_bench/benchmarks/categoricals.py b/asv_bench/benchmarks/categoricals.py index e21d859d18c8c..a299e688a13ed 100644 --- a/asv_bench/benchmarks/categoricals.py +++ b/asv_bench/benchmarks/categoricals.py @@ -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) diff --git a/asv_bench/benchmarks/frame_ctor.py b/asv_bench/benchmarks/frame_ctor.py index 3944e0bc523d8..a949ffdced576 100644 --- a/asv_bench/benchmarks/frame_ctor.py +++ b/asv_bench/benchmarks/frame_ctor.py @@ -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) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index 42579becd4237..85de0150a5a28 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -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'}) diff --git a/environment.yml b/environment.yml index e9ac76f5bc52c..a3582c56ee9d2 100644 --- a/environment.yml +++ b/environment.yml @@ -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 diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 817972b3356a2..53689b6bc2eba 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -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] diff --git a/pandas/core/arrays/sparse/scipy_sparse.py b/pandas/core/arrays/sparse/scipy_sparse.py index 11c27451a5801..6ae2903d9826c 100644 --- a/pandas/core/arrays/sparse/scipy_sparse.py +++ b/pandas/core/arrays/sparse/scipy_sparse.py @@ -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 diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ca421e9695888..9c9189e5f8316 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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)) @@ -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()] diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index d8f9db06c5e8c..7b02a99263266 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -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(): @@ -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), ) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 96fd4c6bdc6e5..d92167f8a3b19 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -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": { diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index bb8d15896b727..453d1cca2e085 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -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 " @@ -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 " diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index dba96358227c3..d9e505f0b30cd 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -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) @@ -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) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 03eb8570e436e..7c7b78720d46d 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -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 = [] diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index 3a8e263ac2a6d..601fde80e9a94 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -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) diff --git a/pandas/tests/frame/test_alter_axes.py b/pandas/tests/frame/test_alter_axes.py index 9b76be18b0e88..21470151dcfbd 100644 --- a/pandas/tests/frame/test_alter_axes.py +++ b/pandas/tests/frame/test_alter_axes.py @@ -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))) @@ -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 diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index f694689fa9dfb..9cc9c5dc697b6 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -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) diff --git a/pandas/tests/frame/test_reshape.py b/pandas/tests/frame/test_reshape.py index 5d2c115ce8eb5..5acd681933914 100644 --- a/pandas/tests/frame/test_reshape.py +++ b/pandas/tests/frame/test_reshape.py @@ -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( diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index 18c4d7ceddc65..c41f762e9128d 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -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), diff --git a/pandas/tests/indexes/timedeltas/test_setops.py b/pandas/tests/indexes/timedeltas/test_setops.py index 861067480b5fa..bbdd6c8c7c017 100644 --- a/pandas/tests/indexes/timedeltas/test_setops.py +++ b/pandas/tests/indexes/timedeltas/test_setops.py @@ -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): @@ -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): @@ -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): diff --git a/pandas/tests/indexing/multiindex/test_loc.py b/pandas/tests/indexing/multiindex/test_loc.py index 9eeee897bfbb5..76425c72ce4f9 100644 --- a/pandas/tests/indexing/multiindex/test_loc.py +++ b/pandas/tests/indexing/multiindex/test_loc.py @@ -1,5 +1,3 @@ -import itertools - import numpy as np import pytest @@ -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:] diff --git a/pandas/tests/indexing/multiindex/test_xs.py b/pandas/tests/indexing/multiindex/test_xs.py index 99f343c2f4a7d..c81712b1e0496 100644 --- a/pandas/tests/indexing/multiindex/test_xs.py +++ b/pandas/tests/indexing/multiindex/test_xs.py @@ -1,5 +1,3 @@ -from itertools import product - import numpy as np import pytest @@ -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") diff --git a/pandas/tests/indexing/test_categorical.py b/pandas/tests/indexing/test_categorical.py index 6c81a00cb8f34..ab3b0ed13b5c0 100644 --- a/pandas/tests/indexing/test_categorical.py +++ b/pandas/tests/indexing/test_categorical.py @@ -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): diff --git a/pandas/tests/io/formats/test_to_excel.py b/pandas/tests/io/formats/test_to_excel.py index 1440b0a6f06f1..4d8edec7c7f14 100644 --- a/pandas/tests/io/formats/test_to_excel.py +++ b/pandas/tests/io/formats/test_to_excel.py @@ -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")] ), diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py index a43da75005a65..d79280f9ea494 100644 --- a/pandas/tests/io/pytables/test_store.py +++ b/pandas/tests/io/pytables/test_store.py @@ -2806,16 +2806,16 @@ def test_select_iterator(self, setup_path): expected = store.select("df") - results = [s for s in store.select("df", iterator=True)] + results = list(store.select("df", iterator=True)) result = concat(results) tm.assert_frame_equal(expected, result) - results = [s for s in store.select("df", chunksize=100)] + results = list(store.select("df", chunksize=100)) assert len(results) == 5 result = concat(results) tm.assert_frame_equal(expected, result) - results = [s for s in store.select("df", chunksize=150)] + results = list(store.select("df", chunksize=150)) result = concat(results) tm.assert_frame_equal(result, expected) @@ -2835,7 +2835,7 @@ def test_select_iterator(self, setup_path): df = tm.makeTimeDataFrame(500) df.to_hdf(path, "df", format="table") - results = [s for s in read_hdf(path, "df", chunksize=100)] + results = list(read_hdf(path, "df", chunksize=100)) result = concat(results) assert len(results) == 5 @@ -2856,12 +2856,9 @@ def test_select_iterator(self, setup_path): # full selection expected = store.select_as_multiple(["df1", "df2"], selector="df1") - results = [ - s - for s in store.select_as_multiple( - ["df1", "df2"], selector="df1", chunksize=150 - ) - ] + results = list( + store.select_as_multiple(["df1", "df2"], selector="df1", chunksize=150) + ) result = concat(results) tm.assert_frame_equal(expected, result) @@ -2916,19 +2913,19 @@ def test_select_iterator_complete_8014(self, setup_path): end_dt = expected.index[-1] # select w/iterator and no where clause works - results = [s for s in store.select("df", chunksize=chunksize)] + results = list(store.select("df", chunksize=chunksize)) result = concat(results) tm.assert_frame_equal(expected, result) # select w/iterator and where clause, single term, begin of range where = "index >= '{beg_dt}'".format(beg_dt=beg_dt) - results = [s for s in store.select("df", where=where, chunksize=chunksize)] + results = list(store.select("df", where=where, chunksize=chunksize)) result = concat(results) tm.assert_frame_equal(expected, result) # select w/iterator and where clause, single term, end of range where = "index <= '{end_dt}'".format(end_dt=end_dt) - results = [s for s in store.select("df", where=where, chunksize=chunksize)] + results = list(store.select("df", where=where, chunksize=chunksize)) result = concat(results) tm.assert_frame_equal(expected, result) @@ -2936,7 +2933,7 @@ def test_select_iterator_complete_8014(self, setup_path): where = "index >= '{beg_dt}' & index <= '{end_dt}'".format( beg_dt=beg_dt, end_dt=end_dt ) - results = [s for s in store.select("df", where=where, chunksize=chunksize)] + results = list(store.select("df", where=where, chunksize=chunksize)) result = concat(results) tm.assert_frame_equal(expected, result) @@ -2958,14 +2955,14 @@ def test_select_iterator_non_complete_8014(self, setup_path): # select w/iterator and where clause, single term, begin of range where = "index >= '{beg_dt}'".format(beg_dt=beg_dt) - results = [s for s in store.select("df", where=where, chunksize=chunksize)] + results = list(store.select("df", where=where, chunksize=chunksize)) result = concat(results) rexpected = expected[expected.index >= beg_dt] tm.assert_frame_equal(rexpected, result) # select w/iterator and where clause, single term, end of range where = "index <= '{end_dt}'".format(end_dt=end_dt) - results = [s for s in store.select("df", where=where, chunksize=chunksize)] + results = list(store.select("df", where=where, chunksize=chunksize)) result = concat(results) rexpected = expected[expected.index <= end_dt] tm.assert_frame_equal(rexpected, result) @@ -2974,7 +2971,7 @@ def test_select_iterator_non_complete_8014(self, setup_path): where = "index >= '{beg_dt}' & index <= '{end_dt}'".format( beg_dt=beg_dt, end_dt=end_dt ) - results = [s for s in store.select("df", where=where, chunksize=chunksize)] + results = list(store.select("df", where=where, chunksize=chunksize)) result = concat(results) rexpected = expected[ (expected.index >= beg_dt) & (expected.index <= end_dt) @@ -2992,7 +2989,7 @@ def test_select_iterator_non_complete_8014(self, setup_path): # select w/iterator and where clause, single term, begin of range where = "index > '{end_dt}'".format(end_dt=end_dt) - results = [s for s in store.select("df", where=where, chunksize=chunksize)] + results = list(store.select("df", where=where, chunksize=chunksize)) assert 0 == len(results) def test_select_iterator_many_empty_frames(self, setup_path): @@ -3014,14 +3011,14 @@ def test_select_iterator_many_empty_frames(self, setup_path): # select w/iterator and where clause, single term, begin of range where = "index >= '{beg_dt}'".format(beg_dt=beg_dt) - results = [s for s in store.select("df", where=where, chunksize=chunksize)] + results = list(store.select("df", where=where, chunksize=chunksize)) result = concat(results) rexpected = expected[expected.index >= beg_dt] tm.assert_frame_equal(rexpected, result) # select w/iterator and where clause, single term, end of range where = "index <= '{end_dt}'".format(end_dt=end_dt) - results = [s for s in store.select("df", where=where, chunksize=chunksize)] + results = list(store.select("df", where=where, chunksize=chunksize)) assert len(results) == 1 result = concat(results) @@ -3032,7 +3029,7 @@ def test_select_iterator_many_empty_frames(self, setup_path): where = "index >= '{beg_dt}' & index <= '{end_dt}'".format( beg_dt=beg_dt, end_dt=end_dt ) - results = [s for s in store.select("df", where=where, chunksize=chunksize)] + results = list(store.select("df", where=where, chunksize=chunksize)) # should be 1, is 10 assert len(results) == 1 @@ -3052,7 +3049,7 @@ def test_select_iterator_many_empty_frames(self, setup_path): where = "index <= '{beg_dt}' & index >= '{end_dt}'".format( beg_dt=beg_dt, end_dt=end_dt ) - results = [s for s in store.select("df", where=where, chunksize=chunksize)] + results = list(store.select("df", where=where, chunksize=chunksize)) # should be [] assert len(results) == 0 diff --git a/pandas/tests/io/sas/test_xport.py b/pandas/tests/io/sas/test_xport.py index 7893877be2033..a52b22122ba81 100644 --- a/pandas/tests/io/sas/test_xport.py +++ b/pandas/tests/io/sas/test_xport.py @@ -104,7 +104,7 @@ def test1_incremental(self): reader = read_sas(self.file01, index="SEQN", chunksize=1000) - all_data = [x for x in reader] + all_data = list(reader) data = pd.concat(all_data, axis=0) tm.assert_frame_equal(data, data_csv, check_index_type=False) diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index debc797fe6e88..5dd671c659263 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -405,7 +405,7 @@ def test_write_ignoring_index(self, engine): ["one", "two", "one", "two", "one", "two", "one", "two"], ] df = pd.DataFrame( - {"one": [i for i in range(8)], "two": [-i for i in range(8)]}, index=arrays + {"one": list(range(8)), "two": [-i for i in range(8)]}, index=arrays ) expected = df.reset_index(drop=True) diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index 940cfef4058e0..c51cd0e92eb3c 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -266,7 +266,7 @@ def test_parallel_coordinates_with_sorted_labels(self): df = DataFrame( { - "feat": [i for i in range(30)], + "feat": list(range(30)), "class": [2 for _ in range(10)] + [3 for _ in range(10)] + [1 for _ in range(10)], @@ -279,8 +279,7 @@ def test_parallel_coordinates_with_sorted_labels(self): ) ordered_color_label_tuples = sorted(color_label_tuples, key=lambda x: x[1]) prev_next_tupels = zip( - [i for i in ordered_color_label_tuples[0:-1]], - [i for i in ordered_color_label_tuples[1:]], + list(ordered_color_label_tuples[0:-1]), list(ordered_color_label_tuples[1:]) ) for prev, nxt in prev_next_tupels: # labels and colors are ordered strictly increasing diff --git a/pandas/tests/reshape/merge/test_join.py b/pandas/tests/reshape/merge/test_join.py index 925eaac45045d..e477b7608ab93 100644 --- a/pandas/tests/reshape/merge/test_join.py +++ b/pandas/tests/reshape/merge/test_join.py @@ -624,7 +624,7 @@ def test_join_mixed_non_unique_index(self): def test_join_non_unique_period_index(self): # GH #16871 index = pd.period_range("2016-01-01", periods=16, freq="M") - df = DataFrame([i for i in range(len(index))], index=index, columns=["pnum"]) + df = DataFrame(list(range(len(index))), index=index, columns=["pnum"]) df2 = concat([df, df]) result = df.join(df2, how="inner", rsuffix="_df2") expected = DataFrame( diff --git a/pandas/tests/reshape/merge/test_merge.py b/pandas/tests/reshape/merge/test_merge.py index dd51a1a6c8359..5f4e8323c7127 100644 --- a/pandas/tests/reshape/merge/test_merge.py +++ b/pandas/tests/reshape/merge/test_merge.py @@ -860,7 +860,7 @@ def test_merge_datetime64tz_with_dst_transition(self): def test_merge_non_unique_period_index(self): # GH #16871 index = pd.period_range("2016-01-01", periods=16, freq="M") - df = DataFrame([i for i in range(len(index))], index=index, columns=["pnum"]) + df = DataFrame(list(range(len(index))), index=index, columns=["pnum"]) df2 = concat([df, df]) result = df.merge(df2, left_index=True, right_index=True, how="inner") expected = DataFrame( diff --git a/pandas/tests/series/test_alter_axes.py b/pandas/tests/series/test_alter_axes.py index 5d74ad95be90d..7a24a45b4b6c2 100644 --- a/pandas/tests/series/test_alter_axes.py +++ b/pandas/tests/series/test_alter_axes.py @@ -233,7 +233,7 @@ def test_reorder_levels(self): def test_rename_axis_mapper(self): # GH 19978 mi = MultiIndex.from_product([["a", "b", "c"], [1, 2]], names=["ll", "nn"]) - s = Series([i for i in range(len(mi))], index=mi) + s = Series(list(range(len(mi))), index=mi) result = s.rename_axis(index={"ll": "foo"}) assert result.index.names == ["foo", "nn"] diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index 656bf5a0e8a44..00c66c8a13bd9 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -261,11 +261,11 @@ def test_tab_completion_with_categorical(self): def get_dir(s): results = [r for r in s.cat.__dir__() if not r.startswith("_")] - return list(sorted(set(results))) + return sorted(set(results)) s = Series(list("aabbcde")).astype("category") results = get_dir(s) - tm.assert_almost_equal(results, list(sorted(set(ok_for_cat)))) + tm.assert_almost_equal(results, sorted(set(ok_for_cat))) @pytest.mark.parametrize( "index", diff --git a/pandas/tests/series/test_datetime_values.py b/pandas/tests/series/test_datetime_values.py index 0be3c729cff91..d038df1747f73 100644 --- a/pandas/tests/series/test_datetime_values.py +++ b/pandas/tests/series/test_datetime_values.py @@ -208,20 +208,18 @@ def compare(s, name): # test limited display api def get_dir(s): results = [r for r in s.dt.__dir__() if not r.startswith("_")] - return list(sorted(set(results))) + return sorted(set(results)) s = Series(date_range("20130101", periods=5, freq="D"), name="xxx") results = get_dir(s) - tm.assert_almost_equal( - results, list(sorted(set(ok_for_dt + ok_for_dt_methods))) - ) + tm.assert_almost_equal(results, sorted(set(ok_for_dt + ok_for_dt_methods))) s = Series( period_range("20130101", periods=5, freq="D", name="xxx").astype(object) ) results = get_dir(s) tm.assert_almost_equal( - results, list(sorted(set(ok_for_period + ok_for_period_methods))) + results, sorted(set(ok_for_period + ok_for_period_methods)) ) # 11295 @@ -229,9 +227,7 @@ def get_dir(s): s = Series(pd.date_range("2015-01-01", "2016-01-01", freq="T"), name="xxx") s = s.dt.tz_localize("UTC").dt.tz_convert("America/Chicago") results = get_dir(s) - tm.assert_almost_equal( - results, list(sorted(set(ok_for_dt + ok_for_dt_methods))) - ) + tm.assert_almost_equal(results, sorted(set(ok_for_dt + ok_for_dt_methods))) exp_values = pd.date_range( "2015-01-01", "2016-01-01", freq="T", tz="UTC" ).tz_convert("America/Chicago") diff --git a/pandas/tests/series/test_duplicates.py b/pandas/tests/series/test_duplicates.py index 4a914e4fb0f2c..0f7e3e307ed19 100644 --- a/pandas/tests/series/test_duplicates.py +++ b/pandas/tests/series/test_duplicates.py @@ -85,7 +85,7 @@ def __ne__(self, other): with capsys.disabled(): li = [Foo(i) for i in range(5)] - s = Series(li, index=[i for i in range(5)]) + s = Series(li, index=list(range(5))) s.is_unique captured = capsys.readouterr() assert len(captured.err) == 0 diff --git a/pandas/tests/series/test_timeseries.py b/pandas/tests/series/test_timeseries.py index 4ae00bca3e832..cf06a9a7c8415 100644 --- a/pandas/tests/series/test_timeseries.py +++ b/pandas/tests/series/test_timeseries.py @@ -604,7 +604,7 @@ def test_asfreq_keep_index_name(self): # GH #9854 index_name = "bar" index = pd.date_range("20130101", periods=20, name=index_name) - df = pd.DataFrame([x for x in range(20)], columns=["foo"], index=index) + df = pd.DataFrame(list(range(20)), columns=["foo"], index=index) assert index_name == df.index.name assert index_name == df.asfreq("10D").index.name diff --git a/pandas/tests/test_base.py b/pandas/tests/test_base.py index 21fed62e51fdf..d9bdceb258592 100644 --- a/pandas/tests/test_base.py +++ b/pandas/tests/test_base.py @@ -653,7 +653,7 @@ def test_value_counts_datetime64(self, klass): # with NaT s = df["dt"].copy() - s = klass([v for v in s.values] + [pd.NaT]) + s = klass(list(s.values) + [pd.NaT]) result = s.value_counts() assert result.index.dtype == "datetime64[ns]" diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index cd6acafc394c5..4d0f0b57c65af 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -257,7 +257,7 @@ def test_repr_name_coincide(self): assert lines[2].startswith("a 0 foo") def test_delevel_infer_dtype(self): - tuples = [tuple for tuple in product(["foo", "bar"], [10, 20], [1.0, 1.1])] + tuples = list(product(["foo", "bar"], [10, 20], [1.0, 1.1])) index = MultiIndex.from_tuples(tuples, names=["prm0", "prm1", "prm2"]) df = DataFrame(np.random.randn(8, 3), columns=["A", "B", "C"], index=index) deleveled = df.reset_index() diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index bed8d2461f65d..e443a7cc932be 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -4253,7 +4253,7 @@ def test_valid_default_arguments(offset_types): cls() -@pytest.mark.parametrize("kwd", sorted(list(liboffsets.relativedelta_kwds))) +@pytest.mark.parametrize("kwd", sorted(liboffsets.relativedelta_kwds)) def test_valid_month_attributes(kwd, month_classes): # GH#18226 cls = month_classes @@ -4262,14 +4262,14 @@ def test_valid_month_attributes(kwd, month_classes): cls(**{kwd: 3}) -@pytest.mark.parametrize("kwd", sorted(list(liboffsets.relativedelta_kwds))) +@pytest.mark.parametrize("kwd", sorted(liboffsets.relativedelta_kwds)) def test_valid_relativedelta_kwargs(kwd): # Check that all the arguments specified in liboffsets.relativedelta_kwds # are in fact valid relativedelta keyword args DateOffset(**{kwd: 1}) -@pytest.mark.parametrize("kwd", sorted(list(liboffsets.relativedelta_kwds))) +@pytest.mark.parametrize("kwd", sorted(liboffsets.relativedelta_kwds)) def test_valid_tick_attributes(kwd, tick_classes): # GH#18226 cls = tick_classes diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 2b4cb322fc966..bcd12eba1651a 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1952,7 +1952,7 @@ def keyfunc(x): label = "{prefix}_l{i}_g{j}".format(prefix=prefix, i=i, j=j) cnt[label] = ndupe_l[i] # cute Counter trick - result = list(sorted(cnt.elements(), key=keyfunc))[:nentries] + result = sorted(cnt.elements(), key=keyfunc)[:nentries] tuples.append(result) tuples = list(zip(*tuples)) diff --git a/requirements-dev.txt b/requirements-dev.txt index 13e2c95126f0c..6235b61d92f29 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,7 +6,7 @@ cython>=0.29.13 black<=19.3b0 cpplint flake8 -flake8-comprehensions +flake8-comprehensions>=3.1.0 flake8-rst>=0.6.0,<=0.7.0 isort mypy==0.720