diff --git a/pandas/core/computation/pytables.py b/pandas/core/computation/pytables.py
index f0f3e7f19db50..043f05ca0a38f 100644
--- a/pandas/core/computation/pytables.py
+++ b/pandas/core/computation/pytables.py
@@ -211,7 +211,7 @@ def stringify(value):
kind = ensure_decoded(self.kind)
meta = ensure_decoded(self.meta)
- if kind == "datetime64" or kind == "datetime":
+ if kind in ("datetime64", "datetime"):
if isinstance(v, (int, float)):
v = stringify(v)
v = ensure_decoded(v)
@@ -219,7 +219,7 @@ def stringify(value):
if v.tz is not None:
v = v.tz_convert("UTC")
return TermValue(v, v.value, kind)
- elif kind == "timedelta64" or kind == "timedelta":
+ elif kind in ("timedelta64", "timedelta"):
if isinstance(v, str):
v = Timedelta(v).value
else:
diff --git a/pandas/core/frame.py b/pandas/core/frame.py
index 0737836bf412f..062cd27b9a3eb 100644
--- a/pandas/core/frame.py
+++ b/pandas/core/frame.py
@@ -1754,7 +1754,7 @@ def from_dict(
# error: Incompatible types in assignment (expression has type
# "List[Any]", variable has type "Dict[Any, Any]")
data = list(data.values()) # type: ignore[assignment]
- elif orient == "columns" or orient == "tight":
+ elif orient in ("columns", "tight"):
if columns is not None:
raise ValueError(f"cannot use columns parameter with orient='{orient}'")
else: # pragma: no cover
diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py
index 1ae5b97cc0913..c35a0d5229070 100644
--- a/pandas/core/indexes/base.py
+++ b/pandas/core/indexes/base.py
@@ -4066,7 +4066,7 @@ def _check_indexing_method(
"method='nearest' not implemented yet "
"for MultiIndex; see GitHub issue 9365"
)
- elif method == "pad" or method == "backfill":
+ elif method in ("pad", "backfill"):
if tolerance is not None:
raise NotImplementedError(
"tolerance not implemented yet for MultiIndex"
diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py
index dafa5e9680eec..d80eefb09afbe 100644
--- a/pandas/core/indexes/datetimelike.py
+++ b/pandas/core/indexes/datetimelike.py
@@ -663,7 +663,7 @@ def _get_insert_freq(self, loc: int, item):
if self.size:
if item is NaT:
pass
- elif (loc == 0 or loc == -len(self)) and item + self.freq == self[0]:
+ elif loc in (0, -len(self)) and item + self.freq == self[0]:
freq = self.freq
elif (loc == len(self)) and item - self.freq == self[-1]:
freq = self.freq
diff --git a/pandas/core/indexes/range.py b/pandas/core/indexes/range.py
index 64a8d0d1ed54c..de50f86756c7a 100644
--- a/pandas/core/indexes/range.py
+++ b/pandas/core/indexes/range.py
@@ -833,11 +833,11 @@ def delete(self, loc) -> Index: # type: ignore[override]
# In some cases we can retain RangeIndex, see also
# DatetimeTimedeltaMixin._get_delete_Freq
if is_integer(loc):
- if loc == 0 or loc == -len(self):
+ if loc in (0, -len(self)):
return self[1:]
- if loc == -1 or loc == len(self) - 1:
+ if loc in (-1, len(self) - 1):
return self[:-1]
- if len(self) == 3 and (loc == 1 or loc == -2):
+ if len(self) == 3 and loc in (1, -2):
return self[::2]
elif lib.is_list_like(loc):
diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py
index 36a3281b7b931..326e6c4251152 100644
--- a/pandas/core/nanops.py
+++ b/pandas/core/nanops.py
@@ -183,7 +183,7 @@ def _bn_ok_dtype(dtype: DtypeObj, name: str) -> bool:
def _has_infs(result) -> bool:
if isinstance(result, np.ndarray):
- if result.dtype == "f8" or result.dtype == "f4":
+ if result.dtype in ("f8", "f4"):
# Note: outside of an nanops-specific test, we always have
# result.ndim == 1, so there is no risk of this ravel making a copy.
return lib.has_infs(result.ravel("K"))
diff --git a/pandas/core/ops/__init__.py b/pandas/core/ops/__init__.py
index d08bc1b6756c4..4007d3cfa46da 100644
--- a/pandas/core/ops/__init__.py
+++ b/pandas/core/ops/__init__.py
@@ -397,7 +397,7 @@ def _maybe_align_series_as_frame(frame: DataFrame, series: Series, axis: AxisInt
rvalues = series._values
if not isinstance(rvalues, np.ndarray):
# TODO(EA2D): no need to special-case with 2D EAs
- if rvalues.dtype == "datetime64[ns]" or rvalues.dtype == "timedelta64[ns]":
+ if rvalues.dtype in ("datetime64[ns]", "timedelta64[ns]"):
# We can losslessly+cheaply cast to ndarray
rvalues = np.asarray(rvalues)
else:
diff --git a/pandas/io/formats/excel.py b/pandas/io/formats/excel.py
index ce7f663dd5703..466ffe5ac1b49 100644
--- a/pandas/io/formats/excel.py
+++ b/pandas/io/formats/excel.py
@@ -277,7 +277,7 @@ def _border_style(self, style: str | None, width: str | None, color: str | None)
# Return "none" will keep "border" in style dictionary
return "none"
- if style == "none" or style == "hidden":
+ if style in ("none", "hidden"):
return "none"
width_name = self._get_width_name(width)
diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py
index db3c86b734cf4..155465c358b5e 100644
--- a/pandas/io/formats/style.py
+++ b/pandas/io/formats/style.py
@@ -4210,7 +4210,7 @@ def css_calc(x, left: float, right: float, align: str, color: str | list | tuple
z, align = align(values), "zero"
elif isinstance(align, (float, int)):
z, align = float(align), "zero"
- elif not (align == "left" or align == "right" or align == "zero"):
+ elif align not in ("left", "right", "zero"):
raise ValueError(
"`align` should be in {'left', 'right', 'mid', 'mean', 'zero'} or be a "
"value defining the center line or a callable that returns a float"
diff --git a/pandas/io/formats/style_render.py b/pandas/io/formats/style_render.py
index b8ea0374c0288..6d815b43a9bcd 100644
--- a/pandas/io/formats/style_render.py
+++ b/pandas/io/formats/style_render.py
@@ -2228,14 +2228,14 @@ def _parse_latex_css_conversion(styles: CSSList) -> CSSList:
"""
def font_weight(value, arg):
- if value == "bold" or value == "bolder":
+ if value in ("bold", "bolder"):
return "bfseries", f"{arg}"
return None
def font_style(value, arg):
if value == "italic":
return "itshape", f"{arg}"
- elif value == "oblique":
+ if value == "oblique":
return "slshape", f"{arg}"
return None
diff --git a/pandas/io/html.py b/pandas/io/html.py
index 3cfd450e48257..a08b73d94250b 100644
--- a/pandas/io/html.py
+++ b/pandas/io/html.py
@@ -527,7 +527,7 @@ def _expand_colspan_rowspan(
# Append the text from this
, colspan times
text = _remove_whitespace(self._text_getter(td))
- if self.extract_links == "all" or self.extract_links == section:
+ if self.extract_links in ("all", section):
href = self._href_getter(td)
text = (text, href)
rowspan = int(self._attr_getter(td, "rowspan") or 1)
diff --git a/pandas/io/json/_json.py b/pandas/io/json/_json.py
index 90c81e06ca06a..4bf883a7214bf 100644
--- a/pandas/io/json/_json.py
+++ b/pandas/io/json/_json.py
@@ -1146,7 +1146,7 @@ def _try_convert_data(
pass
# don't coerce 0-len data
- if len(data) and (data.dtype == "float" or data.dtype == "object"):
+ if len(data) and data.dtype in ("float", "object"):
# coerce ints if we can
try:
diff --git a/pandas/io/parsers/python_parser.py b/pandas/io/parsers/python_parser.py
index c3b196f538463..daf89319a4520 100644
--- a/pandas/io/parsers/python_parser.py
+++ b/pandas/io/parsers/python_parser.py
@@ -788,9 +788,9 @@ def _next_iter_line(self, row_num: int) -> list[Scalar] | None:
assert isinstance(line, list)
return line
except csv.Error as e:
- if (
- self.on_bad_lines == self.BadLineHandleMethod.ERROR
- or self.on_bad_lines == self.BadLineHandleMethod.WARN
+ if self.on_bad_lines in (
+ self.BadLineHandleMethod.ERROR,
+ self.BadLineHandleMethod.WARN,
):
msg = str(e)
@@ -1013,9 +1013,9 @@ def _rows_to_cols(self, content: list[list[Scalar]]) -> list[np.ndarray]:
new_l = self.on_bad_lines(l)
if new_l is not None:
content.append(new_l)
- elif (
- self.on_bad_lines == self.BadLineHandleMethod.ERROR
- or self.on_bad_lines == self.BadLineHandleMethod.WARN
+ elif self.on_bad_lines in (
+ self.BadLineHandleMethod.ERROR,
+ self.BadLineHandleMethod.WARN,
):
row_num = self.pos - (content_len - i + footers)
bad_lines.append((row_num, actual_len))
diff --git a/pandas/io/parsers/readers.py b/pandas/io/parsers/readers.py
index c1698c68ce465..81ffa74693156 100644
--- a/pandas/io/parsers/readers.py
+++ b/pandas/io/parsers/readers.py
@@ -2229,7 +2229,7 @@ def _merge_with_dialect_properties(
# Don't warn if the default parameter was passed in,
# even if it conflicts with the dialect (gh-23761).
- if provided != parser_default and provided != dialect_val:
+ if provided not in (parser_default, dialect_val):
msg = (
f"Conflicting values for '{param}': '{provided}' was "
f"provided, but the dialect specifies '{dialect_val}'. "
diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py
index a95d1b9d7cce6..ab3151f01b31f 100644
--- a/pandas/io/pytables.py
+++ b/pandas/io/pytables.py
@@ -618,7 +618,7 @@ def __contains__(self, key: str) -> bool:
node = self.get_node(key)
if node is not None:
name = node._v_pathname
- if name == key or name[1:] == key:
+ if key in (name, name[1:]):
return True
return False
@@ -3006,7 +3006,7 @@ def read_index_node(
attrs = node._v_attrs
factory, kwargs = self._get_index_factory(attrs)
- if kind == "date" or kind == "object":
+ if kind in ("date", "object"):
index = factory(
_unconvert_index(
data, kind, encoding=self.encoding, errors=self.errors
@@ -5243,7 +5243,7 @@ def __init__(
# see if we have a passed coordinate like
with suppress(ValueError):
inferred = lib.infer_dtype(where, skipna=False)
- if inferred == "integer" or inferred == "boolean":
+ if inferred in ("integer", "boolean"):
where = np.asarray(where)
if where.dtype == np.bool_:
start, stop = self.start, self.stop
diff --git a/pandas/io/sas/sas7bdat.py b/pandas/io/sas/sas7bdat.py
index a60c1eb025218..80efef211ece5 100644
--- a/pandas/io/sas/sas7bdat.py
+++ b/pandas/io/sas/sas7bdat.py
@@ -431,10 +431,7 @@ def _process_page_metadata(self) -> None:
subheader_processor = self._subheader_processors[subheader_index]
if subheader_processor is None:
- f1 = (
- subheader_compression == const.compressed_subheader_id
- or subheader_compression == 0
- )
+ f1 = subheader_compression in (const.compressed_subheader_id, 0)
f2 = subheader_type == const.compressed_subheader_type
if self.compression and f1 and f2:
self._current_page_data_subheader_pointers.append(
diff --git a/pandas/io/sql.py b/pandas/io/sql.py
index 305fc8ba4b040..783b5f8cd63ae 100644
--- a/pandas/io/sql.py
+++ b/pandas/io/sql.py
@@ -1178,7 +1178,7 @@ def _sqlalchemy_type(self, col):
Time,
)
- if col_type == "datetime64" or col_type == "datetime":
+ if col_type in ("datetime64", "datetime"):
# GH 9086: TIMESTAMP is the suggested type if the column contains
# timezone information
try:
diff --git a/pandas/io/stata.py b/pandas/io/stata.py
index 06cba7388b294..037aeb5339818 100644
--- a/pandas/io/stata.py
+++ b/pandas/io/stata.py
@@ -2178,7 +2178,7 @@ def _dtype_to_default_stata_fmt(
return "%9.0g"
elif dtype == np.int32:
return "%12.0g"
- elif dtype == np.int8 or dtype == np.int16:
+ elif dtype in (np.int8, np.int16):
return "%8.0g"
else: # pragma : no cover
raise NotImplementedError(f"Data type {dtype} not supported.")
diff --git a/pandas/tests/apply/test_frame_apply.py b/pandas/tests/apply/test_frame_apply.py
index 3bcb7d964fad1..a7aefc9b1eaa0 100644
--- a/pandas/tests/apply/test_frame_apply.py
+++ b/pandas/tests/apply/test_frame_apply.py
@@ -1342,7 +1342,7 @@ def test_size_as_str(how, axis):
# Just a string attribute arg same as calling df.arg
# on the columns
result = getattr(df, how)("size", axis=axis)
- if axis == 0 or axis == "index":
+ if axis in (0, "index"):
expected = Series(df.shape[0], index=df.columns)
else:
expected = Series(df.shape[1], index=df.index)
diff --git a/pandas/tests/apply/test_frame_transform.py b/pandas/tests/apply/test_frame_transform.py
index 2d4deff8ebc4a..c7a99400ab8e1 100644
--- a/pandas/tests/apply/test_frame_transform.py
+++ b/pandas/tests/apply/test_frame_transform.py
@@ -69,7 +69,7 @@ def test_transform_empty_listlike(float_frame, ops, frame_or_series):
@pytest.mark.parametrize("box", [dict, Series])
def test_transform_dictlike(axis, float_frame, box):
# GH 35964
- if axis == 0 or axis == "index":
+ if axis in (0, "index"):
e = float_frame.columns[0]
expected = float_frame[[e]].transform(np.abs)
else:
diff --git a/pandas/tests/apply/test_str.py b/pandas/tests/apply/test_str.py
index 38b2a5459eb1f..36182c46bfd67 100644
--- a/pandas/tests/apply/test_str.py
+++ b/pandas/tests/apply/test_str.py
@@ -236,7 +236,7 @@ def test_agg_cython_table_transform_frame(df, func, expected, axis):
# GH 21224
# test transforming functions in
# pandas.core.base.SelectionMixin._cython_table (cumprod, cumsum)
- if axis == "columns" or axis == 1:
+ if axis in ("columns", 1):
# operating blockwise doesn't let us preserve dtypes
expected = expected.astype("float64")
@@ -273,7 +273,7 @@ def test_transform_groupby_kernel_frame(request, axis, float_frame, op):
# GH 35964
args = [0.0] if op == "fillna" else []
- if axis == 0 or axis == "index":
+ if axis in (0, "index"):
ones = np.ones(float_frame.shape[0])
else:
ones = np.ones(float_frame.shape[1])
@@ -286,7 +286,7 @@ def test_transform_groupby_kernel_frame(request, axis, float_frame, op):
float_frame["E"] = float_frame["A"].copy()
assert len(float_frame._mgr.arrays) > 1
- if axis == 0 or axis == "index":
+ if axis in (0, "index"):
ones = np.ones(float_frame.shape[0])
else:
ones = np.ones(float_frame.shape[1])
diff --git a/pandas/tests/frame/methods/test_interpolate.py b/pandas/tests/frame/methods/test_interpolate.py
index 7d6cf43c530a7..6543fd8efdf1b 100644
--- a/pandas/tests/frame/methods/test_interpolate.py
+++ b/pandas/tests/frame/methods/test_interpolate.py
@@ -383,7 +383,7 @@ def test_interp_string_axis(self, axis_name, axis_number):
@pytest.mark.parametrize("method", ["ffill", "bfill", "pad"])
def test_interp_fillna_methods(self, request, axis, method, using_array_manager):
# GH 12918
- if using_array_manager and (axis == 1 or axis == "columns"):
+ if using_array_manager and axis in (1, "columns"):
# TODO(ArrayManager) support axis=1
td.mark_array_manager_not_yet_implemented(request)
diff --git a/pandas/tests/indexes/test_setops.py b/pandas/tests/indexes/test_setops.py
index 4cb8e95f32e6b..1939a30ad66ce 100644
--- a/pandas/tests/indexes/test_setops.py
+++ b/pandas/tests/indexes/test_setops.py
@@ -103,7 +103,7 @@ def test_union_different_types(index_flat, index_flat2, request):
# complex objects non-sortable
warn = RuntimeWarning
- any_uint64 = idx1.dtype == np.uint64 or idx2.dtype == np.uint64
+ any_uint64 = np.uint64 in (idx1.dtype, idx2.dtype)
idx1_signed = is_signed_integer_dtype(idx1.dtype)
idx2_signed = is_signed_integer_dtype(idx2.dtype)
diff --git a/pandas/tests/indexing/multiindex/test_slice.py b/pandas/tests/indexing/multiindex/test_slice.py
index 91ea1f7cec324..b059839746eef 100644
--- a/pandas/tests/indexing/multiindex/test_slice.py
+++ b/pandas/tests/indexing/multiindex/test_slice.py
@@ -35,7 +35,7 @@ def test_per_axis_per_level_getitem(self):
d,
)
for a, b, c, d in df.index.values
- if (a == "A1" or a == "A2" or a == "A3") and (c == "C1" or c == "C3")
+ if a in ("A1", "A2", "A3") and c in ("C1", "C3")
]
]
tm.assert_frame_equal(result, expected)
@@ -49,8 +49,7 @@ def test_per_axis_per_level_getitem(self):
d,
)
for a, b, c, d in df.index.values
- if (a == "A1" or a == "A2" or a == "A3")
- and (c == "C1" or c == "C2" or c == "C3")
+ if a in ("A1", "A2", "A3") and c in ("C1", "C2", "C3")
]
]
result = df.loc[(slice("A1", "A3"), slice(None), slice("C1", "C3")), :]
@@ -121,7 +120,7 @@ def test_per_axis_per_level_getitem(self):
d,
)
for a, b, c, d in s.index.values
- if (a == "A1" or a == "A2" or a == "A3") and (c == "C1" or c == "C3")
+ if a in ("A1", "A2", "A3") and c in ("C1", "C3")
]
]
tm.assert_series_equal(result, expected)
@@ -416,7 +415,7 @@ def test_per_axis_per_level_doc_examples(self):
d,
)
for a, b, c, d in df.index.values
- if (a == "A1" or a == "A2" or a == "A3") and (c == "C1" or c == "C3")
+ if a in ("A1", "A2", "A3") and c in ("C1", "C3")
]
]
tm.assert_frame_equal(result, expected)
@@ -433,7 +432,7 @@ def test_per_axis_per_level_doc_examples(self):
d,
)
for a, b, c, d in df.index.values
- if (c == "C1" or c == "C3")
+ if c in ("C1", "C3")
]
]
tm.assert_frame_equal(result, expected)
@@ -494,7 +493,7 @@ def test_loc_axis_arguments(self):
d,
)
for a, b, c, d in df.index.values
- if (a == "A1" or a == "A2" or a == "A3") and (c == "C1" or c == "C3")
+ if a in ("A1", "A2", "A3") and c in ("C1", "C3")
]
]
tm.assert_frame_equal(result, expected)
@@ -509,7 +508,7 @@ def test_loc_axis_arguments(self):
d,
)
for a, b, c, d in df.index.values
- if (c == "C1" or c == "C3")
+ if c in ("C1", "C3")
]
]
tm.assert_frame_equal(result, expected)
diff --git a/pandas/tests/io/excel/test_readers.py b/pandas/tests/io/excel/test_readers.py
index fa1d6bbfd5a7e..362e8146fd291 100644
--- a/pandas/tests/io/excel/test_readers.py
+++ b/pandas/tests/io/excel/test_readers.py
@@ -1222,7 +1222,7 @@ def test_read_excel_nrows_non_integer_parameter(self, read_ext):
("testmultiindex", "both", [0, 1], [0, 1], None),
("testmultiindex", "mi_column_name", [0, 1], 0, None),
("testskiprows", "skiprows_list", None, None, [0, 2]),
- ("testskiprows", "skiprows_list", None, None, lambda x: x == 0 or x == 2),
+ ("testskiprows", "skiprows_list", None, None, lambda x: x in (0, 2)),
],
)
def test_read_excel_nrows_params(
diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py
index ef4a172f07b0a..749075b8637cf 100644
--- a/pandas/tests/io/json/test_pandas.py
+++ b/pandas/tests/io/json/test_pandas.py
@@ -24,7 +24,7 @@
def assert_json_roundtrip_equal(result, expected, orient):
- if orient == "records" or orient == "values":
+ if orient in ("records", "values"):
expected = expected.reset_index(drop=True)
if orient == "values":
expected.columns = range(len(expected.columns))
diff --git a/pandas/tests/util/test_assert_series_equal.py b/pandas/tests/util/test_assert_series_equal.py
index 25f5b31eb4664..4665077696b2b 100644
--- a/pandas/tests/util/test_assert_series_equal.py
+++ b/pandas/tests/util/test_assert_series_equal.py
@@ -115,9 +115,7 @@ def test_less_precise(data1, data2, dtype, decimals):
s1 = Series([data1], dtype=dtype)
s2 = Series([data2], dtype=dtype)
- if (decimals == 5 or decimals == 10) or (
- decimals >= 3 and abs(data1 - data2) >= 0.0005
- ):
+ if decimals in (5, 10) or (decimals >= 3 and abs(data1 - data2) >= 0.0005):
if is_extension_array_dtype(dtype):
msg = "ExtensionArray are different"
else:
diff --git a/pandas/tseries/frequencies.py b/pandas/tseries/frequencies.py
index 97dcd0b011b62..a7fe2da703908 100644
--- a/pandas/tseries/frequencies.py
+++ b/pandas/tseries/frequencies.py
@@ -642,7 +642,7 @@ def _is_quarterly(rule: str) -> bool:
def _is_monthly(rule: str) -> bool:
rule = rule.upper()
- return rule == "M" or rule == "BM"
+ return rule in ("M", "BM")
def _is_weekly(rule: str) -> bool:
diff --git a/pandas/tseries/holiday.py b/pandas/tseries/holiday.py
index a8e55c4c2522f..cb65fc958414f 100644
--- a/pandas/tseries/holiday.py
+++ b/pandas/tseries/holiday.py
@@ -54,9 +54,9 @@ def next_monday_or_tuesday(dt: datetime) -> datetime:
(because Monday is already taken by adjacent holiday on the day before)
"""
dow = dt.weekday()
- if dow == 5 or dow == 6:
+ if dow in (5, 6):
return dt + timedelta(2)
- elif dow == 0:
+ if dow == 0:
return dt + timedelta(1)
return dt
diff --git a/pyproject.toml b/pyproject.toml
index b8568f1839f42..be753a7f2e614 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -114,7 +114,6 @@ disable = [
"consider-merging-isinstance",
"consider-using-from-import",
"consider-using-get",
- "consider-using-in",
"consider-using-min-builtin",
"consider-using-sys-exit",
"consider-using-ternary",
diff --git a/setup.py b/setup.py
index 0e489c4c9b017..f0a81779a90b6 100755
--- a/setup.py
+++ b/setup.py
@@ -30,7 +30,7 @@
def is_platform_windows():
- return sys.platform == "win32" or sys.platform == "cygwin"
+ return sys.platform in ("win32", "cygwin")
def is_platform_mac():
|