Skip to content

STYLE: fix pylint simplifiable-if-statement warnings #49323

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

Merged
merged 2 commits into from
Oct 26, 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
10 changes: 2 additions & 8 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,10 +986,7 @@ def is_dtype(cls, dtype: object) -> bool:
# but doesn't regard freq str like "U" as dtype.
if dtype.startswith("period[") or dtype.startswith("Period["):
try:
if cls._parse_dtype_strict(dtype) is not None:
return True
else:
return False
return bool(cls._parse_dtype_strict(dtype) is not None)
except ValueError:
return False
else:
Expand Down Expand Up @@ -1254,10 +1251,7 @@ def is_dtype(cls, dtype: object) -> bool:
if isinstance(dtype, str):
if dtype.lower().startswith("interval"):
try:
if cls.construct_from_string(dtype) is not None:
return True
else:
return False
return bool(cls.construct_from_string(dtype) is not None)
Copy link
Member

Choose a reason for hiding this comment

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

is should always give boolean so could lose the bool? Same above

except (ValueError, TypeError):
return False
else:
Expand Down
10 changes: 2 additions & 8 deletions pandas/io/formats/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,7 @@ def non_null_counts(self) -> Sequence[int]:

@property
def memory_usage_bytes(self) -> int:
if self.memory_usage == "deep":
deep = True
else:
deep = False
deep = bool(self.memory_usage == "deep")
return self.data.memory_usage(index=True, deep=deep).sum()

def render(
Expand Down Expand Up @@ -579,10 +576,7 @@ def memory_usage_bytes(self) -> int:
memory_usage_bytes : int
Object's total memory usage in bytes.
"""
if self.memory_usage == "deep":
deep = True
else:
deep = False
deep = bool(self.memory_usage == "deep")
Copy link
Member

Choose a reason for hiding this comment

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

Similar comment - could you remove the bool here?

return self.data.memory_usage(index=True, deep=deep)


Expand Down
6 changes: 1 addition & 5 deletions pandas/tests/tseries/offsets/test_week.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ def test_is_on_offset(self, weekday):

for day in range(1, 8):
date = datetime(2008, 1, day)

if day % 7 == weekday:
expected = True
else:
expected = False
expected = bool(day % 7 == weekday)
Copy link
Member

Choose a reason for hiding this comment

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

Same for this one also

assert_is_on_offset(offset, date, expected)

@pytest.mark.parametrize(
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ disable = [
"no-self-use",
"redefined-argument-from-local",
"simplifiable-if-expression",
"simplifiable-if-statement",
"too-few-public-methods",
"too-many-ancestors",
"too-many-arguments",
Expand Down