From 08d6e243e5df0a390afcc00c2001b50e7775fdc3 Mon Sep 17 00:00:00 2001 From: Sai-Suraj-27 Date: Sat, 19 Aug 2023 16:11:13 +0530 Subject: [PATCH 1/3] Updated ruff pre-commit version and modified few lines according to it. --- .pre-commit-config.yaml | 2 +- pandas/core/common.py | 2 +- pandas/core/indexes/base.py | 2 +- pandas/core/internals/construction.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1bda47e0631a0..9f9bcd78c07b0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: hooks: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.284 + rev: v0.0.285 hooks: - id: ruff args: [--exit-non-zero-on-fix] diff --git a/pandas/core/common.py b/pandas/core/common.py index 1679e01ff9fe1..2c33c0563da07 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -138,7 +138,7 @@ def is_bool_indexer(key: Any) -> bool: elif isinstance(key, list): # check if np.array(key).dtype would be bool if len(key) > 0: - if type(key) is not list: + if not isinstance(key, list): # GH#42461 cython will raise TypeError if we pass a subclass key = list(key) return lib.is_bool_list(key) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index ee36a3515c4b3..016b09101b34a 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -7528,7 +7528,7 @@ def ensure_index(index_like: Axes, copy: bool = False) -> Index: index_like = list(index_like) if isinstance(index_like, list): - if type(index_like) is not list: + if not isinstance(index_like, list): # must check for exactly list here because of strict type # check in clean_index_list index_like = list(index_like) diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index 2290cd86f35e6..ed4680c303b19 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -903,7 +903,7 @@ def _list_of_dict_to_arrays( # assure that they are of the base dict class and not of derived # classes - data = [d if type(d) is dict else dict(d) for d in data] + data = [d if isinstance(d, dict) else dict(d) for d in data] content = lib.dicts_to_array(data, list(columns)) return content, columns From 47543a9ad1181b932b7d98b1e8c854863e9ac61d Mon Sep 17 00:00:00 2001 From: Sai-Suraj-27 Date: Sat, 19 Aug 2023 17:58:07 +0530 Subject: [PATCH 2/3] reverted some changes in files, just updating the ruff version. --- pandas/core/common.py | 2 +- pandas/core/indexes/base.py | 2 +- pandas/core/internals/construction.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/common.py b/pandas/core/common.py index 2c33c0563da07..1679e01ff9fe1 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -138,7 +138,7 @@ def is_bool_indexer(key: Any) -> bool: elif isinstance(key, list): # check if np.array(key).dtype would be bool if len(key) > 0: - if not isinstance(key, list): + if type(key) is not list: # GH#42461 cython will raise TypeError if we pass a subclass key = list(key) return lib.is_bool_list(key) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 016b09101b34a..ee36a3515c4b3 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -7528,7 +7528,7 @@ def ensure_index(index_like: Axes, copy: bool = False) -> Index: index_like = list(index_like) if isinstance(index_like, list): - if not isinstance(index_like, list): + if type(index_like) is not list: # must check for exactly list here because of strict type # check in clean_index_list index_like = list(index_like) diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index ed4680c303b19..2290cd86f35e6 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -903,7 +903,7 @@ def _list_of_dict_to_arrays( # assure that they are of the base dict class and not of derived # classes - data = [d if isinstance(d, dict) else dict(d) for d in data] + data = [d if type(d) is dict else dict(d) for d in data] content = lib.dicts_to_array(data, list(columns)) return content, columns From 623fc6fec6b34fcbd6dd2e6fa8732c5c1c136df3 Mon Sep 17 00:00:00 2001 From: Sai-Suraj-27 Date: Sat, 19 Aug 2023 18:07:23 +0530 Subject: [PATCH 3/3] Added #noqa E721 comment for the lines where new ruff is failing. --- pandas/core/common.py | 2 +- pandas/core/indexes/base.py | 2 +- pandas/core/internals/construction.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/common.py b/pandas/core/common.py index 1679e01ff9fe1..8fd8b10c6fc32 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -138,7 +138,7 @@ def is_bool_indexer(key: Any) -> bool: elif isinstance(key, list): # check if np.array(key).dtype would be bool if len(key) > 0: - if type(key) is not list: + if type(key) is not list: # noqa: E721 # GH#42461 cython will raise TypeError if we pass a subclass key = list(key) return lib.is_bool_list(key) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index ee36a3515c4b3..721f4f5e1c494 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -7528,7 +7528,7 @@ def ensure_index(index_like: Axes, copy: bool = False) -> Index: index_like = list(index_like) if isinstance(index_like, list): - if type(index_like) is not list: + if type(index_like) is not list: # noqa: E721 # must check for exactly list here because of strict type # check in clean_index_list index_like = list(index_like) diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index 2290cd86f35e6..82b25955d0def 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -903,7 +903,7 @@ def _list_of_dict_to_arrays( # assure that they are of the base dict class and not of derived # classes - data = [d if type(d) is dict else dict(d) for d in data] + data = [d if type(d) is dict else dict(d) for d in data] # noqa: E721 content = lib.dicts_to_array(data, list(columns)) return content, columns