Skip to content

Commit d13c9e0

Browse files
fabincacarlotta
andauthored
STYLE: fix pylint: no-else-raise (#49520)
* fix pylint: no-else-raise * fix possible imbalanced tuple unpacking warning Co-authored-by: carlotta <[email protected]>
1 parent 62c0fb8 commit d13c9e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+174
-206
lines changed

ci/fix_wheels.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
import zipfile
55

66
try:
7-
_, wheel_path, dest_dir = sys.argv
7+
if len(sys.argv) != 3:
8+
raise ValueError(
9+
"User must pass the path to the wheel and the destination directory."
10+
)
11+
wheel_path = sys.argv[1]
12+
dest_dir = sys.argv[2]
813
# Figure out whether we are building on 32 or 64 bit python
914
is_32 = sys.maxsize <= 2**32
1015
PYTHON_ARCH = "x86" if is_32 else "x64"
@@ -50,5 +55,4 @@
5055
if not success:
5156
os.remove(repaired_wheel_path)
5257
raise exception
53-
else:
54-
print(f"Successfully repaired wheel was written to {repaired_wheel_path}")
58+
print(f"Successfully repaired wheel was written to {repaired_wheel_path}")

doc/make.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ def latex(self, force=False):
259259
"You should check the file "
260260
'"build/latex/pandas.pdf" for problems.'
261261
)
262-
else:
263-
self._run_os("make")
262+
self._run_os("make")
264263
return ret_code
265264

266265
def latex_forced(self):

pandas/_testing/_io.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,7 @@ def wrapper(*args, **kwargs):
243243

244244
if not isinstance(err, error_classes) or raise_on_error:
245245
raise
246-
else:
247-
pytest.skip(
248-
f"Skipping test due to lack of connectivity and error {err}"
249-
)
246+
pytest.skip(f"Skipping test due to lack of connectivity and error {err}")
250247

251248
return wrapper
252249

pandas/compat/_optional.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ def import_optional_dependency(
141141
except ImportError:
142142
if errors == "raise":
143143
raise ImportError(msg)
144-
else:
145-
return None
144+
return None
146145

147146
# Handle submodules: if we have submodule, grab parent module from sys.modules
148147
parent = name.split(".")[0]

pandas/compat/numpy/function.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,7 @@ def validate_resampler_func(method: str, args, kwargs) -> None:
412412
"numpy operations are not valid with resample. "
413413
f"Use .resample(...).{method}() instead"
414414
)
415-
else:
416-
raise TypeError("too many arguments passed in")
415+
raise TypeError("too many arguments passed in")
417416

418417

419418
def validate_minmax_axis(axis: AxisInt | None, ndim: int = 1) -> None:

pandas/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,8 +1163,7 @@ def deco(*args):
11631163
raise ValueError(
11641164
f"Could not find file {path} and --strict-data-files is set."
11651165
)
1166-
else:
1167-
pytest.skip(f"Could not find {path}.")
1166+
pytest.skip(f"Could not find {path}.")
11681167
return path
11691168

11701169
return deco

pandas/core/apply.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ def apply_str(self) -> DataFrame | Series:
464464
"axis" not in arg_names or f in ("corrwith", "skew")
465465
):
466466
raise ValueError(f"Operation {f} does not support axis=1")
467-
elif "axis" in arg_names:
467+
if "axis" in arg_names:
468468
self.kwargs["axis"] = self.axis
469469
return self._try_aggregate_string_function(obj, f, *self.args, **self.kwargs)
470470

@@ -762,7 +762,7 @@ def apply_broadcast(self, target: DataFrame) -> DataFrame:
762762
# must be a scalar or 1d
763763
if ares > 1:
764764
raise ValueError("too many dims to broadcast")
765-
elif ares == 1:
765+
if ares == 1:
766766

767767
# must match return dim
768768
if result_compare != len(res):
@@ -1179,7 +1179,7 @@ def reconstruct_func(
11791179
"Function names must be unique if there is no new column names "
11801180
"assigned"
11811181
)
1182-
elif func is None:
1182+
if func is None:
11831183
# nicer error message
11841184
raise TypeError("Must provide 'func' or tuples of '(column, aggfunc).")
11851185

pandas/core/arrays/datetimelike.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,7 @@ def validate_inferred_freq(
22632263
"values does not conform to passed frequency "
22642264
f"{freq.freqstr}"
22652265
)
2266-
elif freq is None:
2266+
if freq is None:
22672267
freq = inferred_freq
22682268
freq_infer = False
22692269

pandas/core/arrays/datetimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2361,7 +2361,7 @@ def validate_tz_from_dtype(
23612361
if dtz is not None:
23622362
if tz is not None and not timezones.tz_compare(tz, dtz):
23632363
raise ValueError("cannot supply both a tz and a dtype with a tz")
2364-
elif explicit_tz_none:
2364+
if explicit_tz_none:
23652365
raise ValueError("Cannot pass both a timezone-aware dtype and tz=None")
23662366
tz = dtz
23672367

pandas/core/arrays/interval.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,17 +314,17 @@ def _simple_new(
314314
f"right [{type(right).__name__}] types"
315315
)
316316
raise ValueError(msg)
317-
elif is_categorical_dtype(left.dtype) or is_string_dtype(left.dtype):
317+
if is_categorical_dtype(left.dtype) or is_string_dtype(left.dtype):
318318
# GH 19016
319319
msg = (
320320
"category, object, and string subtypes are not supported "
321321
"for IntervalArray"
322322
)
323323
raise TypeError(msg)
324-
elif isinstance(left, ABCPeriodIndex):
324+
if isinstance(left, ABCPeriodIndex):
325325
msg = "Period dtypes are not supported, use a PeriodIndex instead"
326326
raise ValueError(msg)
327-
elif isinstance(left, ABCDatetimeIndex) and str(left.tz) != str(right.tz):
327+
if isinstance(left, ABCDatetimeIndex) and str(left.tz) != str(right.tz):
328328
msg = (
329329
"left and right must have the same time zone, got "
330330
f"'{left.tz}' and '{right.tz}'"
@@ -1321,7 +1321,7 @@ def mid(self) -> Index:
13211321
def overlaps(self, other):
13221322
if isinstance(other, (IntervalArray, ABCIntervalIndex)):
13231323
raise NotImplementedError
1324-
elif not isinstance(other, Interval):
1324+
if not isinstance(other, Interval):
13251325
msg = f"`other` must be Interval-like, got {type(other).__name__}"
13261326
raise TypeError(msg)
13271327

0 commit comments

Comments
 (0)