diff --git a/pandas/_version.py b/pandas/_version.py index 89a3caaf64eae..4877bdff3eb3a 100644 --- a/pandas/_version.py +++ b/pandas/_version.py @@ -73,8 +73,8 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env= assert isinstance(commands, list) p = None for c in commands: + dispcmd = str([c] + args) try: - dispcmd = str([c] + args) # remember shell=False, so use git.cmd on windows, not just git p = subprocess.Popen( [c] + args, diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index b2fe02321ee0c..4c5dbeb6eedf9 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -1309,6 +1309,7 @@ def astype(self, dtype: AstypeArg | None = None, copy: bool = True): values = np.array(self) return astype_nansafe(values, dtype=future_dtype) else: + # pylint: disable-next=used-before-assignment dtype = cast(ExtensionDtype, dtype) cls = dtype.construct_array_type() return cls._from_sequence(self, dtype=dtype, copy=copy) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 6a366fa53e957..4735731e8d6d9 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -260,7 +260,7 @@ def is_scipy_sparse(arr) -> bool: """ global _is_scipy_sparse - if _is_scipy_sparse is None: + if _is_scipy_sparse is None: # pylint: disable=used-before-assignment try: from scipy.sparse import issparse as _is_scipy_sparse except ImportError: diff --git a/pandas/core/groupby/indexing.py b/pandas/core/groupby/indexing.py index 750097b403f26..40eaeea66b25c 100644 --- a/pandas/core/groupby/indexing.py +++ b/pandas/core/groupby/indexing.py @@ -112,6 +112,7 @@ def _positional_selector(self) -> GroupByPositionalSelector: 4 b 5 """ if TYPE_CHECKING: + # pylint: disable-next=used-before-assignment groupby_self = cast(groupby.GroupBy, self) else: groupby_self = self diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index bb2f663dedb33..4cd89d25995bb 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -1060,7 +1060,7 @@ def to_datetime( exact=exact, infer_datetime_format=infer_datetime_format, ) - + # pylint: disable-next=used-before-assignment result: Timestamp | NaTType | Series | Index if isinstance(arg, Timestamp): diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 06d0acfdf440c..30cd707926e05 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -78,7 +78,6 @@ has_mpl = True except ImportError: has_mpl = False - no_mpl_message = "{0} requires matplotlib." @contextmanager @@ -86,7 +85,7 @@ def _mpl(func: Callable) -> Generator[tuple[Any, Any], None, None]: if has_mpl: yield plt, mpl else: - raise ImportError(no_mpl_message.format(func.__name__)) + raise ImportError(f"{func.__name__} requires matplotlib.") #### diff --git a/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index 60ee8943c9916..72bcc074ac32e 100644 --- a/pandas/tests/io/excel/test_writers.py +++ b/pandas/tests/io/excel/test_writers.py @@ -865,11 +865,10 @@ def test_to_excel_output_encoding(self, ext): def test_to_excel_unicode_filename(self, ext): with tm.ensure_clean("\u0192u." + ext) as filename: try: - f = open(filename, "wb") + with open(filename, "wb"): + pass except UnicodeEncodeError: pytest.skip("No unicode file names on this system") - finally: - f.close() df = DataFrame( [[0.123456, 0.234567, 0.567567], [12.32112, 123123.2, 321321.2]], diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py index 3add6e1482687..22873b0096817 100644 --- a/pandas/tests/io/pytables/test_store.py +++ b/pandas/tests/io/pytables/test_store.py @@ -876,13 +876,13 @@ def test_copy(): with catch_warnings(record=True): def do_copy(f, new_f=None, keys=None, propindexes=True, **kwargs): - try: - store = HDFStore(f, "r") + if new_f is None: + import tempfile - if new_f is None: - import tempfile + fd, new_f = tempfile.mkstemp() - fd, new_f = tempfile.mkstemp() + try: + store = HDFStore(f, "r") tstore = store.copy(new_f, keys=keys, propindexes=propindexes, **kwargs) # check keys diff --git a/pyproject.toml b/pyproject.toml index eca46b9417fbe..d30f700a54f80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,7 +75,6 @@ disable = [ "unsubscriptable-object", "unsupported-assignment-operation", "unsupported-membership-test", - "used-before-assignment", # pylint type "C": convention, for programming standard violation "import-outside-toplevel", diff --git a/versioneer.py b/versioneer.py index 1ff2e936e15cc..5dd66e4df6c36 100644 --- a/versioneer.py +++ b/versioneer.py @@ -386,8 +386,8 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env= assert isinstance(commands, list) p = None for c in commands: + dispcmd = str([c] + args) try: - dispcmd = str([c] + args) # remember shell=False, so use git.cmd on windows, not just git p = subprocess.Popen( [c] + args,