Skip to content

Commit

Permalink
STYLE: Fix Pylint Style Checks For used-before-assignment (pandas-dev…
Browse files Browse the repository at this point in the history
…#48940)

* STYLE: Fix Pylint Style Checks For used-before-assignment

* Refactor: Use 'with open' instead of open/close

* CLN: disable used-before-assignment warning

* CLN: Remove used-before-assignment from pyproject.toml

* CLN: disable used-before-assignment warning in-line
  • Loading branch information
Leviob authored and MarcoGorelli committed Nov 18, 2022
1 parent 4aa6057 commit eafc048
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pandas/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pandas/core/groupby/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@
has_mpl = True
except ImportError:
has_mpl = False
no_mpl_message = "{0} requires matplotlib."


@contextmanager
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.")


####
Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/io/excel/test_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/io/pytables/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion versioneer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit eafc048

Please sign in to comment.