Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STYLE: Fix Pylint Style Checks For used-before-assignment #48940

Merged
merged 6 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,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
2 changes: 1 addition & 1 deletion pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,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
4 changes: 3 additions & 1 deletion pandas/core/groupby/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ def _positional_selector(self) -> GroupByPositionalSelector:
4 b 5
"""
if TYPE_CHECKING:
groupby_self = cast(groupby.GroupBy, self)
groupby_self = cast(
groupby.GroupBy, self # pylint: disable=used-before-assignment
)
Leviob marked this conversation as resolved.
Show resolved Hide resolved
else:
groupby_self = self

Expand Down
3 changes: 2 additions & 1 deletion pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,9 @@ def to_datetime(
exact=exact,
infer_datetime_format=infer_datetime_format,
)

# pylint: disable=used-before-assignment
result: Timestamp | NaTType | Series | Index
# pylint: enable=used-before-assignment
Leviob marked this conversation as resolved.
Show resolved Hide resolved

if isinstance(arg, Timestamp):
result = arg
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 @@ -82,15 +82,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
3 changes: 1 addition & 2 deletions pandas/tests/io/excel/test_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,10 +883,9 @@ def test_to_excel_unicode_filename(self, ext):
with tm.ensure_clean("\u0192u." + ext) as filename:
try:
f = open(filename, "wb")
f.close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just:

with open(filename, "wb") as f:
    pass

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart. Thanks.

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 @@ -877,13 +877,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 @@ -63,7 +63,6 @@ disable = [
"unsubscriptable-object",
"unsupported-assignment-operation",
"unsupported-membership-test",
"used-before-assignment",
]

[tool.pytest.ini_options]
Expand Down
2 changes: 1 addition & 1 deletion versioneer.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,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