From 6f49510a510b9d279185eb26fe7ac827891b0b2a Mon Sep 17 00:00:00 2001 From: Thierry Moisan Date: Fri, 28 Oct 2022 21:56:39 -0400 Subject: [PATCH 1/4] STYLE: fix pylint unneeded-not warnings --- pandas/io/formats/style_render.py | 2 +- pandas/tests/arrays/interval/test_interval.py | 4 ++-- pandas/tests/arrays/period/test_arrow_compat.py | 4 ++-- pandas/tests/indexes/multi/test_indexing.py | 2 +- pandas/tests/scalar/timedelta/test_arithmetic.py | 2 +- pandas/tests/scalar/timestamp/test_comparisons.py | 2 +- pyproject.toml | 1 - 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py index 0f93027f3f775..9244a8c5e672d 100644 --- a/pandas/io/formats/style_render.py +++ b/pandas/io/formats/style_render.py @@ -98,7 +98,7 @@ def __init__( self.data: DataFrame = data self.index: Index = data.index self.columns: Index = data.columns - if not isinstance(uuid_len, int) or not uuid_len >= 0: + if not isinstance(uuid_len, int) or uuid_len < 0: raise TypeError("``uuid_len`` must be an integer in range [0, 32].") self.uuid = uuid or uuid4().hex[: min(32, uuid_len)] self.uuid_len = len(self.uuid) diff --git a/pandas/tests/arrays/interval/test_interval.py b/pandas/tests/arrays/interval/test_interval.py index 2a6bea3255342..28b5f441d3cd5 100644 --- a/pandas/tests/arrays/interval/test_interval.py +++ b/pandas/tests/arrays/interval/test_interval.py @@ -256,9 +256,9 @@ def test_arrow_extension_type(): assert p1.closed == "left" assert p1 == p2 - assert not p1 == p3 + assert p1 != p3 assert hash(p1) == hash(p2) - assert not hash(p1) == hash(p3) + assert hash(p1) != hash(p3) @pyarrow_skip diff --git a/pandas/tests/arrays/period/test_arrow_compat.py b/pandas/tests/arrays/period/test_arrow_compat.py index 03fd146572405..61670f74f78fb 100644 --- a/pandas/tests/arrays/period/test_arrow_compat.py +++ b/pandas/tests/arrays/period/test_arrow_compat.py @@ -21,9 +21,9 @@ def test_arrow_extension_type(): assert p1.freq == "D" assert p1 == p2 - assert not p1 == p3 + assert p1 != p3 assert hash(p1) == hash(p2) - assert not hash(p1) == hash(p3) + assert hash(p1) != hash(p3) @pytest.mark.parametrize( diff --git a/pandas/tests/indexes/multi/test_indexing.py b/pandas/tests/indexes/multi/test_indexing.py index fce3da6dd6aee..9b0e74f050b62 100644 --- a/pandas/tests/indexes/multi/test_indexing.py +++ b/pandas/tests/indexes/multi/test_indexing.py @@ -800,7 +800,7 @@ def test_contains_td64_level(self): def test_large_mi_contains(self): # GH#10645 result = MultiIndex.from_arrays([range(10**6), range(10**6)]) - assert not (10**6, 0) in result + assert (10**6, 0) not in result def test_timestamp_multiindex_indexer(): diff --git a/pandas/tests/scalar/timedelta/test_arithmetic.py b/pandas/tests/scalar/timedelta/test_arithmetic.py index 72ee89a4b5108..1c3868bc85fd5 100644 --- a/pandas/tests/scalar/timedelta/test_arithmetic.py +++ b/pandas/tests/scalar/timedelta/test_arithmetic.py @@ -1114,5 +1114,5 @@ def test_ops_error_str(): with pytest.raises(TypeError, match=msg): left > right - assert not left == right + assert not left == right # pylint: disable=unneeded-not assert left != right diff --git a/pandas/tests/scalar/timestamp/test_comparisons.py b/pandas/tests/scalar/timestamp/test_comparisons.py index ad629604d1bc9..c3e0f6df9c7d5 100644 --- a/pandas/tests/scalar/timestamp/test_comparisons.py +++ b/pandas/tests/scalar/timestamp/test_comparisons.py @@ -310,5 +310,5 @@ def __eq__(self, other) -> bool: for left, right in [(inf, timestamp), (timestamp, inf)]: assert left > right or left < right assert left >= right or left <= right - assert not left == right + assert not left == right # pylint: disable=unneeded-not assert left != right diff --git a/pyproject.toml b/pyproject.toml index 397f74ddab71a..223e31dfbb3cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,7 +91,6 @@ disable = [ "unidiomatic-typecheck", "unnecessary-dunder-call", "unnecessary-lambda-assignment", - "unneeded-not", "use-implicit-booleaness-not-comparison", "use-implicit-booleaness-not-len", "use-sequence-for-iteration", From 48a19e825f1af87b1bbd77a63361e0bdb581243c Mon Sep 17 00:00:00 2001 From: Thierry Moisan Date: Fri, 28 Oct 2022 22:49:51 -0400 Subject: [PATCH 2/4] fixup! STYLE: fix pylint unneeded-not warnings --- pandas/tests/arrays/interval/test_interval.py | 2 +- pandas/tests/arrays/period/test_arrow_compat.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/arrays/interval/test_interval.py b/pandas/tests/arrays/interval/test_interval.py index 28b5f441d3cd5..76355d133f023 100644 --- a/pandas/tests/arrays/interval/test_interval.py +++ b/pandas/tests/arrays/interval/test_interval.py @@ -256,7 +256,7 @@ def test_arrow_extension_type(): assert p1.closed == "left" assert p1 == p2 - assert p1 != p3 + assert not p1 == p3 # pylint: disable=unneeded-not assert hash(p1) == hash(p2) assert hash(p1) != hash(p3) diff --git a/pandas/tests/arrays/period/test_arrow_compat.py b/pandas/tests/arrays/period/test_arrow_compat.py index 61670f74f78fb..2322b3a93c957 100644 --- a/pandas/tests/arrays/period/test_arrow_compat.py +++ b/pandas/tests/arrays/period/test_arrow_compat.py @@ -21,7 +21,7 @@ def test_arrow_extension_type(): assert p1.freq == "D" assert p1 == p2 - assert p1 != p3 + assert not p1 == p3 # pylint: disable=unneeded-not assert hash(p1) == hash(p2) assert hash(p1) != hash(p3) From 89185f50a433a621cf14d295093ef4c3599ba092 Mon Sep 17 00:00:00 2001 From: Thierry Moisan Date: Sun, 6 Nov 2022 16:10:29 -0500 Subject: [PATCH 3/4] Add __ne__ method to ArrowPeriodType and ArrowIntervalType --- pandas/core/arrays/arrow/extension_types.py | 6 ++++++ pandas/tests/arrays/interval/test_interval.py | 2 +- pandas/tests/arrays/period/test_arrow_compat.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pandas/core/arrays/arrow/extension_types.py b/pandas/core/arrays/arrow/extension_types.py index c9badb2bd305b..0ed23eab246ca 100644 --- a/pandas/core/arrays/arrow/extension_types.py +++ b/pandas/core/arrays/arrow/extension_types.py @@ -35,6 +35,9 @@ def __eq__(self, other): else: return NotImplemented + def __ne__(self, other) -> bool: + return not self.__eq__(other) + def __hash__(self) -> int: return hash((str(self), self.freq)) @@ -91,6 +94,9 @@ def __eq__(self, other): else: return NotImplemented + def __ne__(self, other) -> bool: + return not self.__eq__(other) + def __hash__(self) -> int: return hash((str(self), str(self.subtype), self.closed)) diff --git a/pandas/tests/arrays/interval/test_interval.py b/pandas/tests/arrays/interval/test_interval.py index 76355d133f023..28b5f441d3cd5 100644 --- a/pandas/tests/arrays/interval/test_interval.py +++ b/pandas/tests/arrays/interval/test_interval.py @@ -256,7 +256,7 @@ def test_arrow_extension_type(): assert p1.closed == "left" assert p1 == p2 - assert not p1 == p3 # pylint: disable=unneeded-not + assert p1 != p3 assert hash(p1) == hash(p2) assert hash(p1) != hash(p3) diff --git a/pandas/tests/arrays/period/test_arrow_compat.py b/pandas/tests/arrays/period/test_arrow_compat.py index 2322b3a93c957..61670f74f78fb 100644 --- a/pandas/tests/arrays/period/test_arrow_compat.py +++ b/pandas/tests/arrays/period/test_arrow_compat.py @@ -21,7 +21,7 @@ def test_arrow_extension_type(): assert p1.freq == "D" assert p1 == p2 - assert not p1 == p3 # pylint: disable=unneeded-not + assert p1 != p3 assert hash(p1) == hash(p2) assert hash(p1) != hash(p3) From b1d188d5464029119852c2674c0103ce4128a884 Mon Sep 17 00:00:00 2001 From: Thierry Moisan Date: Mon, 7 Nov 2022 07:50:35 -0500 Subject: [PATCH 4/4] fixup! Add __ne__ method to ArrowPeriodType and ArrowIntervalType --- pandas/core/arrays/arrow/extension_types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/arrays/arrow/extension_types.py b/pandas/core/arrays/arrow/extension_types.py index 0ed23eab246ca..25f597af5e3cf 100644 --- a/pandas/core/arrays/arrow/extension_types.py +++ b/pandas/core/arrays/arrow/extension_types.py @@ -36,7 +36,7 @@ def __eq__(self, other): return NotImplemented def __ne__(self, other) -> bool: - return not self.__eq__(other) + return not self == other def __hash__(self) -> int: return hash((str(self), self.freq)) @@ -95,7 +95,7 @@ def __eq__(self, other): return NotImplemented def __ne__(self, other) -> bool: - return not self.__eq__(other) + return not self == other def __hash__(self) -> int: return hash((str(self), str(self.subtype), self.closed))