From d7bab206316c53990127c104b03c99c79d96a727 Mon Sep 17 00:00:00 2001 From: Levi Ob Date: Wed, 16 Nov 2022 19:15:23 -0800 Subject: [PATCH 1/3] CLN: Fix pylint undefined-loop-variable warnings --- pandas/core/util/hashing.py | 2 +- pandas/io/excel/_base.py | 2 +- pandas/io/formats/latex.py | 3 +-- pandas/io/formats/printing.py | 4 ++-- pandas/io/formats/style.py | 1 + pandas/tests/frame/methods/test_to_dict_of_blocks.py | 3 +++ pandas/tests/frame/test_iteration.py | 2 +- pandas/tests/io/formats/test_printing.py | 1 + pyproject.toml | 1 - 9 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pandas/core/util/hashing.py b/pandas/core/util/hashing.py index 5a5e46e0227aa..bb38efb26bba4 100644 --- a/pandas/core/util/hashing.py +++ b/pandas/core/util/hashing.py @@ -76,7 +76,7 @@ def combine_hash_arrays( out ^= a out *= mult mult += np.uint64(82520 + inverse_i + inverse_i) - assert i + 1 == num_items, "Fed in wrong num_items" + assert len(arrays) == num_items, "Fed in wrong num_items" out += np.uint64(97531) return out diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 6362e892f0012..7e4b937fc6cf2 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -883,7 +883,7 @@ def parse( if ret_dict: return output else: - return output[asheetname] + return output[asheetname] # pylint: disable=undefined-loop-variable @doc(storage_options=_shared_docs["storage_options"]) diff --git a/pandas/io/formats/latex.py b/pandas/io/formats/latex.py index 4bc9da96885f1..b2622e61896a0 100644 --- a/pandas/io/formats/latex.py +++ b/pandas/io/formats/latex.py @@ -160,8 +160,7 @@ def _get_strcols(self) -> list[list[str]]: def pad_empties(x): for pad in reversed(x): if pad: - break - return [x[0]] + [i if i else " " * len(pad) for i in x[1:]] + return [x[0]] + [i if i else " " * len(pad) for i in x[1:]] gen = (pad_empties(i) for i in out) diff --git a/pandas/io/formats/printing.py b/pandas/io/formats/printing.py index 8091590e2e89d..9cd2853066e14 100644 --- a/pandas/io/formats/printing.py +++ b/pandas/io/formats/printing.py @@ -419,9 +419,9 @@ def best_len(values: list[str]) -> int: for max_items in reversed(range(1, len(value) + 1)): pprinted_seq = _pprint_seq(value, max_seq_items=max_items) if len(pprinted_seq) < max_space: + head = [_pprint_seq(x, max_seq_items=max_items) for x in head] + tail = [_pprint_seq(x, max_seq_items=max_items) for x in tail] break - head = [_pprint_seq(x, max_seq_items=max_items) for x in head] - tail = [_pprint_seq(x, max_seq_items=max_items) for x in tail] summary = "" line = space2 diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 30cd707926e05..2ae827cbe4388 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -2298,6 +2298,7 @@ def set_sticky( "selector": f"thead tr:nth-child({obj.nlevels+1}) th", "props": props + ( + # pylint: disable=undefined-loop-variable f"top:{(i+1) * pixel_size}px; height:{pixel_size}px; " "z-index:2;" ), diff --git a/pandas/tests/frame/methods/test_to_dict_of_blocks.py b/pandas/tests/frame/methods/test_to_dict_of_blocks.py index eb9b78610a112..e8f7360427731 100644 --- a/pandas/tests/frame/methods/test_to_dict_of_blocks.py +++ b/pandas/tests/frame/methods/test_to_dict_of_blocks.py @@ -25,6 +25,7 @@ def test_copy_blocks(self, float_frame): _df.loc[:, column] = _df[column] + 1 # make sure we did not change the original DataFrame + # pylint: disable-next=undefined-loop-variable assert not _df[column].equals(df[column]) def test_no_copy_blocks(self, float_frame, using_copy_on_write): @@ -40,8 +41,10 @@ def test_no_copy_blocks(self, float_frame, using_copy_on_write): if not using_copy_on_write: # make sure we did change the original DataFrame + # pylint: disable-next=undefined-loop-variable assert _df[column].equals(df[column]) else: + # pylint: disable-next=undefined-loop-variable assert not _df[column].equals(df[column]) diff --git a/pandas/tests/frame/test_iteration.py b/pandas/tests/frame/test_iteration.py index c6e5aa6f86d29..1228224a946e2 100644 --- a/pandas/tests/frame/test_iteration.py +++ b/pandas/tests/frame/test_iteration.py @@ -159,4 +159,4 @@ def test_sequence_like_with_categorical(self): str(s) for c, col in df.items(): - str(s) + str(s) # pylint: disable=undefined-loop-variable diff --git a/pandas/tests/io/formats/test_printing.py b/pandas/tests/io/formats/test_printing.py index 5ab7ff085f539..c6a665cbe7b23 100644 --- a/pandas/tests/io/formats/test_printing.py +++ b/pandas/tests/io/formats/test_printing.py @@ -141,6 +141,7 @@ def test_publishes(self, ip): with_latex = pd.option_context("display.latex.repr", True) with opt, with_latex: + # pylint: disable-next=undefined-loop-variable formatted = ipython.display_formatter.format(obj) expected = { diff --git a/pyproject.toml b/pyproject.toml index 0217726514cdb..97a53f8b7eae9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -153,7 +153,6 @@ disable = [ "subprocess-run-check", "super-init-not-called", "try-except-raise", - "undefined-loop-variable", "unnecessary-lambda", "unspecified-encoding", "unused-argument", From 8c91f398ed3a096213986e06953e1d3e5cc390ef Mon Sep 17 00:00:00 2001 From: Levi Ob Date: Wed, 30 Nov 2022 16:34:05 -0800 Subject: [PATCH 2/3] Fix undefined-loop-variable pylint warning --- pandas/core/util/hashing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/util/hashing.py b/pandas/core/util/hashing.py index bb38efb26bba4..db570c6bcf7ff 100644 --- a/pandas/core/util/hashing.py +++ b/pandas/core/util/hashing.py @@ -76,7 +76,8 @@ def combine_hash_arrays( out ^= a out *= mult mult += np.uint64(82520 + inverse_i + inverse_i) - assert len(arrays) == num_items, "Fed in wrong num_items" + # pylint: disable-next=undefined-loop-variable + assert i + 1 == num_items, "Fed in wrong num_items" out += np.uint64(97531) return out From 10b612ae528c3d00f6f0b555cf3d4815409dbc0e Mon Sep 17 00:00:00 2001 From: Levi Ob Date: Sun, 18 Dec 2022 15:00:42 -0800 Subject: [PATCH 3/3] CLN: Format props f-strings for clarity --- pandas/io/formats/style.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index eb99fdea2ba47..16e0bd572e5d1 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -2298,9 +2298,8 @@ def set_sticky( "selector": f"thead tr:nth-child({obj.nlevels+1}) th", "props": props + ( - f"top:{(len(levels_)) * pixel_size}px; \ - height:{pixel_size}px; " - "z-index:2;" + f"top:{(len(levels_)) * pixel_size}px; " + f"height:{pixel_size}px; z-index:2;" ), } )