diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index feda414a0113d..dc89c11bef231 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -2104,11 +2104,10 @@ def __call__(self, num: float) -> str: if self.use_eng_prefix: prefix = self.ENG_PREFIXES[int_pow10] + elif int_pow10 < 0: + prefix = f"E-{-int_pow10:02d}" else: - if int_pow10 < 0: - prefix = f"E-{-int_pow10:02d}" - else: - prefix = f"E+{int_pow10:02d}" + prefix = f"E+{int_pow10:02d}" mant = sign * dnum / (10**pow10) diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index 7f31c354b5c85..260620e145105 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -660,14 +660,13 @@ def _create_table_builder(self) -> DataFrameTableBuilder: ) elif self.verbose is False: # specifically set to False, not necessarily None return DataFrameTableBuilderNonVerbose(info=self.info) + elif self.exceeds_info_cols: + return DataFrameTableBuilderNonVerbose(info=self.info) else: - if self.exceeds_info_cols: - return DataFrameTableBuilderNonVerbose(info=self.info) - else: - return DataFrameTableBuilderVerbose( - info=self.info, - with_counts=self.show_counts, - ) + return DataFrameTableBuilderVerbose( + info=self.info, + with_counts=self.show_counts, + ) class SeriesInfoPrinter(InfoPrinterAbstract): diff --git a/pandas/io/formats/printing.py b/pandas/io/formats/printing.py index e734304471144..58c2d0a9aa574 100644 --- a/pandas/io/formats/printing.py +++ b/pandas/io/formats/printing.py @@ -272,10 +272,9 @@ class TableSchemaFormatter(BaseFormatter): formatters[mimetype] = TableSchemaFormatter() # enable it if it's been disabled: formatters[mimetype].enabled = True - else: - # unregister tableschema mime-type - if mimetype in formatters: - formatters[mimetype].enabled = False + # unregister tableschema mime-type + elif mimetype in formatters: + formatters[mimetype].enabled = False def default_pprint(thing: Any, max_seq_items: int | None = None) -> str: diff --git a/pandas/io/parquet.py b/pandas/io/parquet.py index 0936544929071..b4330349a8c9d 100644 --- a/pandas/io/parquet.py +++ b/pandas/io/parquet.py @@ -134,9 +134,8 @@ def validate_dataframe(df: DataFrame) -> None: each level of the MultiIndex """ ) - else: - if df.columns.inferred_type not in {"string", "empty"}: - raise ValueError("parquet must have string column names") + elif df.columns.inferred_type not in {"string", "empty"}: + raise ValueError("parquet must have string column names") # index level names must be strings valid_names = all( diff --git a/pandas/io/parsers/arrow_parser_wrapper.py b/pandas/io/parsers/arrow_parser_wrapper.py index ddbd902acdb08..b920e660c290b 100644 --- a/pandas/io/parsers/arrow_parser_wrapper.py +++ b/pandas/io/parsers/arrow_parser_wrapper.py @@ -116,10 +116,9 @@ def _finalize_pandas_output(self, frame: DataFrame) -> DataFrame: for i, item in enumerate(self.index_col): if is_integer(item): self.index_col[i] = frame.columns[item] - else: - # String case - if item not in frame.columns: - raise ValueError(f"Index {item} invalid") + # String case + elif item not in frame.columns: + raise ValueError(f"Index {item} invalid") frame.set_index(self.index_col, drop=True, inplace=True) # Clear names if headerless and no name given if self.header is None and not multi_index_named: diff --git a/pandas/io/parsers/c_parser_wrapper.py b/pandas/io/parsers/c_parser_wrapper.py index f463647d5a464..e87a34ddee0ff 100644 --- a/pandas/io/parsers/c_parser_wrapper.py +++ b/pandas/io/parsers/c_parser_wrapper.py @@ -395,26 +395,23 @@ def _concatenate_chunks(chunks: list[dict[int, ArrayLike]]) -> dict: dtype = dtypes.pop() if is_categorical_dtype(dtype): result[name] = union_categoricals(arrs, sort_categories=False) + elif isinstance(dtype, ExtensionDtype): + # TODO: concat_compat? + array_type = dtype.construct_array_type() + # error: Argument 1 to "_concat_same_type" of "ExtensionArray" + # has incompatible type "List[Union[ExtensionArray, ndarray]]"; + # expected "Sequence[ExtensionArray]" + result[name] = array_type._concat_same_type(arrs) # type: ignore[arg-type] else: - if isinstance(dtype, ExtensionDtype): - # TODO: concat_compat? - array_type = dtype.construct_array_type() - # error: Argument 1 to "_concat_same_type" of "ExtensionArray" - # has incompatible type "List[Union[ExtensionArray, ndarray]]"; - # expected "Sequence[ExtensionArray]" - result[name] = array_type._concat_same_type( - arrs # type: ignore[arg-type] - ) - else: - # error: Argument 1 to "concatenate" has incompatible - # type "List[Union[ExtensionArray, ndarray[Any, Any]]]" - # ; expected "Union[_SupportsArray[dtype[Any]], - # Sequence[_SupportsArray[dtype[Any]]], - # Sequence[Sequence[_SupportsArray[dtype[Any]]]], - # Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]] - # , Sequence[Sequence[Sequence[Sequence[ - # _SupportsArray[dtype[Any]]]]]]]" - result[name] = np.concatenate(arrs) # type: ignore[arg-type] + # error: Argument 1 to "concatenate" has incompatible + # type "List[Union[ExtensionArray, ndarray[Any, Any]]]" + # ; expected "Union[_SupportsArray[dtype[Any]], + # Sequence[_SupportsArray[dtype[Any]]], + # Sequence[Sequence[_SupportsArray[dtype[Any]]]], + # Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]] + # , Sequence[Sequence[Sequence[Sequence[ + # _SupportsArray[dtype[Any]]]]]]]" + result[name] = np.concatenate(arrs) # type: ignore[arg-type] if warning_columns: warning_names = ",".join(warning_columns) diff --git a/pandas/io/parsers/python_parser.py b/pandas/io/parsers/python_parser.py index 5b30596eebf6f..315d18d052d9f 100644 --- a/pandas/io/parsers/python_parser.py +++ b/pandas/io/parsers/python_parser.py @@ -556,20 +556,19 @@ def _infer_columns( columns = self._handle_usecols( columns, columns[0], num_original_columns ) + elif self.usecols is None or len(names) >= num_original_columns: + columns = self._handle_usecols([names], names, num_original_columns) + num_original_columns = len(names) + elif not callable(self.usecols) and len(names) != len(self.usecols): + raise ValueError( + "Number of passed names did not match number of " + "header fields in the file" + ) else: - if self.usecols is None or len(names) >= num_original_columns: - columns = self._handle_usecols([names], names, num_original_columns) - num_original_columns = len(names) - else: - if not callable(self.usecols) and len(names) != len(self.usecols): - raise ValueError( - "Number of passed names did not match number of " - "header fields in the file" - ) - # Ignore output but set used columns. - self._handle_usecols([names], names, ncols) - columns = [names] - num_original_columns = ncols + # Ignore output but set used columns. + self._handle_usecols([names], names, ncols) + columns = [names] + num_original_columns = ncols return columns, num_original_columns, unnamed_cols diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index bd427ec98e8dc..58a8482fd3988 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -2197,9 +2197,8 @@ def update_info(self, info) -> None: f"existing_value [{existing_value}] conflicts with " f"new value [{value}]" ) - else: - if value is not None or existing_value is not None: - idx[key] = value + elif value is not None or existing_value is not None: + idx[key] = value def set_info(self, info) -> None: """set my state from the passed info""" diff --git a/pandas/io/xml.py b/pandas/io/xml.py index 17c6f92847d5c..25ef098881a92 100644 --- a/pandas/io/xml.py +++ b/pandas/io/xml.py @@ -241,40 +241,39 @@ def _parse_nodes(self, elems: list[Any]) -> list[dict[str, str | None]]: for el in elems ] - else: - if self.names: - dicts = [ - { - **el.attrib, - **( - {el.tag: el.text.strip()} - if el.text and not el.text.isspace() - else {} - ), - **{ - nm: ch.text.strip() if ch.text else None - for nm, ch in zip(self.names, el.findall("*")) - }, - } - for el in elems - ] + elif self.names: + dicts = [ + { + **el.attrib, + **( + {el.tag: el.text.strip()} + if el.text and not el.text.isspace() + else {} + ), + **{ + nm: ch.text.strip() if ch.text else None + for nm, ch in zip(self.names, el.findall("*")) + }, + } + for el in elems + ] - else: - dicts = [ - { - **el.attrib, - **( - {el.tag: el.text.strip()} - if el.text and not el.text.isspace() - else {} - ), - **{ - ch.tag: ch.text.strip() if ch.text else None - for ch in el.findall("*") - }, - } - for el in elems - ] + else: + dicts = [ + { + **el.attrib, + **( + {el.tag: el.text.strip()} + if el.text and not el.text.isspace() + else {} + ), + **{ + ch.tag: ch.text.strip() if ch.text else None + for ch in el.findall("*") + }, + } + for el in elems + ] dicts = [ {k.split("}")[1] if "}" in k else k: v for k, v in d.items()} for d in dicts diff --git a/pandas/plotting/_matplotlib/boxplot.py b/pandas/plotting/_matplotlib/boxplot.py index e2f30da1b839c..ad054b6065756 100644 --- a/pandas/plotting/_matplotlib/boxplot.py +++ b/pandas/plotting/_matplotlib/boxplot.py @@ -403,11 +403,10 @@ def plot_group(keys, values, ax: Axes, **kwds): colors = _get_colors() if column is None: columns = None + elif isinstance(column, (list, tuple)): + columns = column else: - if isinstance(column, (list, tuple)): - columns = column - else: - columns = [column] + columns = [column] if by is not None: # Prefer array return type for 2-D plots to match the subplot layout @@ -523,11 +522,10 @@ def boxplot_frame_groupby( keys, frames = zip(*grouped) if grouped.axis == 0: df = pd.concat(frames, keys=keys, axis=1) + elif len(frames) > 1: + df = frames[0].join(frames[1::]) else: - if len(frames) > 1: - df = frames[0].join(frames[1::]) - else: - df = frames[0] + df = frames[0] # GH 16748, DataFrameGroupby fails when subplots=False and `column` argument # is assigned, and in this case, since `df` here becomes MI after groupby, diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 754cc94b6ded6..94e416e2a2e8a 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -164,17 +164,16 @@ def __init__( if isinstance(data, DataFrame): if column: self.columns = com.maybe_make_list(column) + elif self.by is None: + self.columns = [ + col for col in data.columns if is_numeric_dtype(data[col]) + ] else: - if self.by is None: - self.columns = [ - col for col in data.columns if is_numeric_dtype(data[col]) - ] - else: - self.columns = [ - col - for col in data.columns - if col not in self.by and is_numeric_dtype(data[col]) - ] + self.columns = [ + col + for col in data.columns + if col not in self.by and is_numeric_dtype(data[col]) + ] # For `hist` plot, need to get grouped original data before `self.data` is # updated later @@ -504,15 +503,14 @@ def _setup_subplots(self): layout=self.layout, layout_type=self._layout_type, ) + elif self.ax is None: + fig = self.plt.figure(figsize=self.figsize) + axes = fig.add_subplot(111) else: - if self.ax is None: - fig = self.plt.figure(figsize=self.figsize) - axes = fig.add_subplot(111) - else: - fig = self.ax.get_figure() - if self.figsize is not None: - fig.set_size_inches(self.figsize) - axes = self.ax + fig = self.ax.get_figure() + if self.figsize is not None: + fig.set_size_inches(self.figsize) + axes = self.ax axes = flatten_axes(axes) @@ -1225,14 +1223,13 @@ def _make_plot(self): if self.colormap is not None: cmap = mpl.colormaps.get_cmap(self.colormap) + # cmap is only used if c_values are integers, otherwise UserWarning + elif is_integer_dtype(c_values): + # pandas uses colormap, matplotlib uses cmap. + cmap = "Greys" + cmap = mpl.colormaps[cmap] else: - # cmap is only used if c_values are integers, otherwise UserWarning - if is_integer_dtype(c_values): - # pandas uses colormap, matplotlib uses cmap. - cmap = "Greys" - cmap = mpl.colormaps[cmap] - else: - cmap = None + cmap = None if color_by_categorical: from matplotlib import colors @@ -1630,14 +1627,13 @@ def __init__(self, data, **kwargs) -> None: self.lim_offset = self.bar_width / 2 else: self.lim_offset = 0 + elif kwargs["align"] == "edge": + w = self.bar_width / self.nseries + self.tickoffset = self.bar_width * (pos - 0.5) + w * 0.5 + self.lim_offset = w * 0.5 else: - if kwargs["align"] == "edge": - w = self.bar_width / self.nseries - self.tickoffset = self.bar_width * (pos - 0.5) + w * 0.5 - self.lim_offset = w * 0.5 - else: - self.tickoffset = self.bar_width * pos - self.lim_offset = 0 + self.tickoffset = self.bar_width * pos + self.lim_offset = 0 self.ax_pos = self.tick_pos - self.tickoffset diff --git a/pandas/plotting/_matplotlib/timeseries.py b/pandas/plotting/_matplotlib/timeseries.py index 8e21b2c691185..ab051ee58da70 100644 --- a/pandas/plotting/_matplotlib/timeseries.py +++ b/pandas/plotting/_matplotlib/timeseries.py @@ -216,9 +216,9 @@ def use_dynamic_x(ax: Axes, data: DataFrame | Series) -> bool: if freq is None: # convert irregular if axes has freq info freq = ax_freq - else: # do not use tsplot if irregular was plotted first - if (ax_freq is None) and (len(ax.get_lines()) > 0): - return False + # do not use tsplot if irregular was plotted first + elif (ax_freq is None) and (len(ax.get_lines()) > 0): + return False if freq is None: return False diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index f0fb0a0595cbd..0bcb766a08237 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -105,11 +105,10 @@ def _check_align(df, cond, other, check_dtypes=True): if is_scalar(other): o = other + elif isinstance(other, np.ndarray): + o = Series(other[:, i], index=result.index).values else: - if isinstance(other, np.ndarray): - o = Series(other[:, i], index=result.index).values - else: - o = other[k].values + o = other[k].values new_values = d if c.all() else np.where(c, d, o) expected = Series(new_values, index=result.index, name=k) diff --git a/pandas/tests/frame/methods/test_set_axis.py b/pandas/tests/frame/methods/test_set_axis.py index fd140e0098f2a..6ae53fff8dd28 100644 --- a/pandas/tests/frame/methods/test_set_axis.py +++ b/pandas/tests/frame/methods/test_set_axis.py @@ -66,15 +66,14 @@ def test_set_axis_copy(self, obj, using_copy_on_write): tm.shares_memory(result.iloc[:, i], obj.iloc[:, i]) for i in range(obj.shape[1]) ) + # check we DID make a copy + elif obj.ndim == 1: + assert not tm.shares_memory(result, obj) else: - # check we DID make a copy - if obj.ndim == 1: - assert not tm.shares_memory(result, obj) - else: - assert not any( - tm.shares_memory(result.iloc[:, i], obj.iloc[:, i]) - for i in range(obj.shape[1]) - ) + assert not any( + tm.shares_memory(result.iloc[:, i], obj.iloc[:, i]) + for i in range(obj.shape[1]) + ) res = obj.set_axis(new_index, copy=False) tm.assert_equal(expected, res) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 569ec613cbcb9..711eb924925d6 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -2976,13 +2976,10 @@ def constructor(self, frame_or_series, box): ) else: return lambda x, **kwargs: frame_or_series({"A": x}, **extra, **kwargs) + elif frame_or_series is Series: + return lambda x, **kwargs: frame_or_series([x, x], **extra, **kwargs) else: - if frame_or_series is Series: - return lambda x, **kwargs: frame_or_series([x, x], **extra, **kwargs) - else: - return lambda x, **kwargs: frame_or_series( - {"A": [x, x]}, **extra, **kwargs - ) + return lambda x, **kwargs: frame_or_series({"A": [x, x]}, **extra, **kwargs) @pytest.mark.parametrize("dtype", ["M8[ns]", "m8[ns]"]) def test_from_nat_scalar(self, dtype, constructor): diff --git a/pandas/tests/groupby/test_groupby_dropna.py b/pandas/tests/groupby/test_groupby_dropna.py index 31a8e7a7d36ac..95184bfd770d1 100644 --- a/pandas/tests/groupby/test_groupby_dropna.py +++ b/pandas/tests/groupby/test_groupby_dropna.py @@ -552,12 +552,11 @@ def test_categorical_reducers( expected = expected.set_index(["x", "x2"]) else: expected = expected.set_index("x") - else: - if index_kind != "range" and reduction_func != "size": - # size, unlike other methods, has the desired behavior in GH#49519 - expected = expected.drop(columns="x") - if index_kind == "multi": - expected = expected.drop(columns="x2") + elif index_kind != "range" and reduction_func != "size": + # size, unlike other methods, has the desired behavior in GH#49519 + expected = expected.drop(columns="x") + if index_kind == "multi": + expected = expected.drop(columns="x2") if reduction_func in ("idxmax", "idxmin") and index_kind != "range": # expected was computed with a RangeIndex; need to translate to index values values = expected["y"].values.tolist() diff --git a/pandas/tests/indexes/test_numpy_compat.py b/pandas/tests/indexes/test_numpy_compat.py index 07ebe6fa04beb..5e2e2b9bbec21 100644 --- a/pandas/tests/indexes/test_numpy_compat.py +++ b/pandas/tests/indexes/test_numpy_compat.py @@ -92,14 +92,13 @@ def test_numpy_ufuncs_basic(index, func): else: # e.g. np.exp with Int64 -> Float64 assert type(result) is Index + # raise AttributeError or TypeError + elif len(index) == 0: + pass else: - # raise AttributeError or TypeError - if len(index) == 0: - pass - else: - with tm.external_error_raised((TypeError, AttributeError)): - with np.errstate(all="ignore"): - func(index) + with tm.external_error_raised((TypeError, AttributeError)): + with np.errstate(all="ignore"): + func(index) @pytest.mark.parametrize( @@ -144,12 +143,11 @@ def test_numpy_ufuncs_other(index, func): else: tm.assert_numpy_array_equal(out, result) + elif len(index) == 0: + pass else: - if len(index) == 0: - pass - else: - with tm.external_error_raised(TypeError): - func(index) + with tm.external_error_raised(TypeError): + func(index) @pytest.mark.parametrize("func", [np.maximum, np.minimum]) diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index 9cccd2c45c9e7..3b622d7b4703a 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -29,11 +29,10 @@ def check(self, result, original, indexer, getitem): """ if isinstance(original, Series): expected = original.iloc[indexer] + elif getitem: + expected = original.iloc[:, indexer] else: - if getitem: - expected = original.iloc[:, indexer] - else: - expected = original.iloc[indexer] + expected = original.iloc[indexer] tm.assert_almost_equal(result, expected) diff --git a/pandas/tests/scalar/timedelta/test_timedelta.py b/pandas/tests/scalar/timedelta/test_timedelta.py index 7046055b5c0d5..4cb77b2f1d065 100644 --- a/pandas/tests/scalar/timedelta/test_timedelta.py +++ b/pandas/tests/scalar/timedelta/test_timedelta.py @@ -749,17 +749,15 @@ def checker(ts, nanos, unit): with pytest.raises(err_cls, match=msg): method(ts, unit) return - else: - if mod >= diff: - if ub > cls.max._value: - with pytest.raises(err_cls, match=msg): - method(ts, unit) - return - else: - if lb < cls.min._value: - with pytest.raises(err_cls, match=msg): - method(ts, unit) - return + elif mod >= diff: + if ub > cls.max._value: + with pytest.raises(err_cls, match=msg): + method(ts, unit) + return + elif lb < cls.min._value: + with pytest.raises(err_cls, match=msg): + method(ts, unit) + return res = method(ts, unit) diff --git a/pandas/tests/scalar/timestamp/test_unary_ops.py b/pandas/tests/scalar/timestamp/test_unary_ops.py index 5a082fb91a03e..2fee395886cff 100644 --- a/pandas/tests/scalar/timestamp/test_unary_ops.py +++ b/pandas/tests/scalar/timestamp/test_unary_ops.py @@ -345,17 +345,15 @@ def checker(ts, nanos, unit): with pytest.raises(err_cls, match=msg): method(ts, unit) return - else: - if mod >= diff: - if ub > cls.max._value: - with pytest.raises(err_cls, match=msg): - method(ts, unit) - return - else: - if lb < cls.min._value: - with pytest.raises(err_cls, match=msg): - method(ts, unit) - return + elif mod >= diff: + if ub > cls.max._value: + with pytest.raises(err_cls, match=msg): + method(ts, unit) + return + elif lb < cls.min._value: + with pytest.raises(err_cls, match=msg): + method(ts, unit) + return res = method(ts, unit) diff --git a/pandas/tests/tslibs/test_conversion.py b/pandas/tests/tslibs/test_conversion.py index bf9a45c6d9d7a..42d2bc01f5e67 100644 --- a/pandas/tests/tslibs/test_conversion.py +++ b/pandas/tests/tslibs/test_conversion.py @@ -110,11 +110,10 @@ def test_length_zero_copy(dtype, copy): result = astype_overflowsafe(arr, copy=copy, dtype=np.dtype("M8[ns]")) if copy: assert not np.shares_memory(result, arr) + elif arr.dtype == result.dtype: + assert result is arr else: - if arr.dtype == result.dtype: - assert result is arr - else: - assert not np.shares_memory(result, arr) + assert not np.shares_memory(result, arr) def test_ensure_datetime64ns_bigendian(): diff --git a/pandas/util/_validators.py b/pandas/util/_validators.py index b60169f8364da..7b1eca695c6d6 100644 --- a/pandas/util/_validators.py +++ b/pandas/util/_validators.py @@ -328,9 +328,8 @@ def validate_percentile(q: float | Iterable[float]) -> np.ndarray: if q_arr.ndim == 0: if not 0 <= q_arr <= 1: raise ValueError(msg.format(q_arr / 100.0)) - else: - if not all(0 <= qs <= 1 for qs in q_arr): - raise ValueError(msg.format(q_arr / 100.0)) + elif not all(0 <= qs <= 1 for qs in q_arr): + raise ValueError(msg.format(q_arr / 100.0)) return q_arr diff --git a/pyproject.toml b/pyproject.toml index 07913b7895500..ddce400a90ebb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -290,6 +290,8 @@ exclude = [ [tool.ruff.per-file-ignores] # relative imports allowed for asv_bench "asv_bench/*" = ["TID"] +# to be enabled gradually +"pandas/core/*" = ["PLR5501"] # TCH to be enabled gradually "pandas/core/arrays/*" = ["TCH"] "pandas/core/nanops.py" = ["TCH"] diff --git a/scripts/validate_unwanted_patterns.py b/scripts/validate_unwanted_patterns.py index dbccb91f809d1..5d2a989b5e150 100755 --- a/scripts/validate_unwanted_patterns.py +++ b/scripts/validate_unwanted_patterns.py @@ -139,15 +139,14 @@ def bare_pytest_raises(file_obj: IO[str]) -> Iterable[Tuple[int, str]]: "Bare pytests raise have been found. " "Please pass in the argument 'match' as well the exception.", ) - else: - # Means that there are arguments that are being passed in, - # now we validate that `match` is one of the passed in arguments - if not any(keyword.arg == "match" for keyword in node.keywords): - yield ( - node.lineno, - "Bare pytests raise have been found. " - "Please pass in the argument 'match' as well the exception.", - ) + # Means that there are arguments that are being passed in, + # now we validate that `match` is one of the passed in arguments + elif not any(keyword.arg == "match" for keyword in node.keywords): + yield ( + node.lineno, + "Bare pytests raise have been found. " + "Please pass in the argument 'match' as well the exception.", + ) PRIVATE_FUNCTIONS_ALLOWED = {"sys._getframe"} # no known alternative