Skip to content

Commit 2580e0a

Browse files
committed
Replace while loops
1 parent de4eaf8 commit 2580e0a

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

pandas/core/strings/accessor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def cons_row(x):
423423
result.name = name
424424
return result
425425

426-
def _get_series_list(self, others):
426+
def _get_series_list(self, others) -> list[Series]:
427427
"""
428428
Auxiliary function for :meth:`str.cat`. Turn potentially mixed input
429429
into a list of Series (elements without an index must match the length
@@ -474,8 +474,8 @@ def _get_series_list(self, others):
474474
for x in others
475475
):
476476
los: list[Series] = []
477-
while others: # iterate through list and append each element
478-
los = los + self._get_series_list(others.pop(0))
477+
for other in others:
478+
los.extend(self._get_series_list(other))
479479
return los
480480
# ... or just strings
481481
elif all(not is_list_like(x) for x in others):

pandas/plotting/_matplotlib/tools.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# being a bit too dynamic
22
from __future__ import annotations
33

4-
from math import ceil
4+
from math import (
5+
ceil,
6+
floor,
7+
log2,
8+
)
59
from typing import TYPE_CHECKING
610
import warnings
711

@@ -126,9 +130,7 @@ def _get_layout(
126130
try:
127131
return layouts[nplots]
128132
except KeyError:
129-
k = 1
130-
while k**2 < nplots:
131-
k += 1
133+
k = floor(log2(nplots))
132134

133135
if (k - 1) * k >= nplots:
134136
return k, (k - 1)

pandas/tseries/holiday.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ def next_workday(dt: datetime) -> datetime:
116116
returns next workday used for observances
117117
"""
118118
dt += timedelta(days=1)
119-
while dt.weekday() > 4:
120-
# Mon-Fri are 0-4
121-
dt += timedelta(days=1)
119+
# Mon-Fri are 0-4
120+
dt += timedelta(days=max(dt.weekday() - 4, 0))
122121
return dt
123122

124123

@@ -127,9 +126,8 @@ def previous_workday(dt: datetime) -> datetime:
127126
returns previous workday used for observances
128127
"""
129128
dt -= timedelta(days=1)
130-
while dt.weekday() > 4:
131-
# Mon-Fri are 0-4
132-
dt -= timedelta(days=1)
129+
# Mon-Fri are 0-4
130+
dt -= timedelta(days=max(dt.weekday() - 4, 0))
133131
return dt
134132

135133

0 commit comments

Comments
 (0)