Skip to content

Commit 309c7de

Browse files
committed
Undo max/min rule from ruff
1 parent 8e2534e commit 309c7de

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

pandas/core/_numba/kernels/min_max_.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ def grouped_min_max(
112112
continue
113113

114114
if is_max:
115-
output[lab] = max(val, output[lab])
115+
if val > output[lab]:
116+
output[lab] = val
116117
else:
117-
output[lab] = min(val, output[lab])
118+
if val < output[lab]:
119+
output[lab] = val
118120

119121
# Set labels that don't satisfy min_periods as np.nan
120122
for lab, count in enumerate(nobs):

pandas/core/dtypes/cast.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,9 @@ def _maybe_promote(dtype: np.dtype, fill_value=np.nan):
683683

684684
elif dtype.kind == "f":
685685
mst = np.min_scalar_type(fill_value)
686-
dtype = max(mst, dtype)
686+
if mst > dtype:
687+
# e.g. mst is np.float64 and dtype is np.float32
688+
dtype = mst
687689

688690
elif dtype.kind == "c":
689691
mst = np.min_scalar_type(fill_value)
@@ -716,7 +718,9 @@ def _maybe_promote(dtype: np.dtype, fill_value=np.nan):
716718

717719
elif dtype.kind == "c":
718720
mst = np.min_scalar_type(fill_value)
719-
dtype = max(mst, dtype)
721+
if mst > dtype:
722+
# e.g. mst is np.complex128 and dtype is np.complex64
723+
dtype = mst
720724

721725
else:
722726
dtype = np.dtype(np.object_)

pandas/io/excel/_odfreader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def get_sheet_data(
142142
empty_cells = 0
143143
table_row.extend([value] * column_repeat)
144144

145-
max_row_len = max(max_row_len, len(table_row))
145+
if max_row_len < len(table_row):
146+
max_row_len = len(table_row)
146147

147148
row_repeat = self._get_row_repeat(sheet_row)
148149
if len(table_row) == 0:

pandas/tests/arithmetic/test_numeric.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ def test_numeric_arr_rdiv_tdscalar(self, three_days, numeric_idx, box_with_array
274274
expected = TimedeltaIndex(["3 Days", "36 Hours"])
275275
if isinstance(three_days, np.timedelta64):
276276
dtype = three_days.dtype
277-
dtype = max(dtype, np.dtype("m8[s]"))
277+
if dtype < np.dtype("m8[s]"):
278+
# i.e. resolution is lower -> use lowest supported resolution
279+
dtype = np.dtype("m8[s]")
278280
expected = expected.astype(dtype)
279281
elif type(three_days) is timedelta:
280282
expected = expected.astype("m8[us]")

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ ignore = [
324324
"PT019",
325325
# The following rules may cause conflicts when used with the formatter:
326326
"ISC001",
327-
327+
# if-stmt-min-max
328+
"PLR1730",
328329

329330
### TODO: Enable gradually
330331
# Useless statement

0 commit comments

Comments
 (0)