Skip to content

Commit

Permalink
Replace while loops
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Nov 1, 2024
1 parent de4eaf8 commit 2580e0a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions pandas/core/strings/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def cons_row(x):
result.name = name
return result

def _get_series_list(self, others):
def _get_series_list(self, others) -> list[Series]:
"""
Auxiliary function for :meth:`str.cat`. Turn potentially mixed input
into a list of Series (elements without an index must match the length
Expand Down Expand Up @@ -474,8 +474,8 @@ def _get_series_list(self, others):
for x in others
):
los: list[Series] = []
while others: # iterate through list and append each element
los = los + self._get_series_list(others.pop(0))
for other in others:
los.extend(self._get_series_list(other))
return los
# ... or just strings
elif all(not is_list_like(x) for x in others):
Expand Down
10 changes: 6 additions & 4 deletions pandas/plotting/_matplotlib/tools.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# being a bit too dynamic
from __future__ import annotations

from math import ceil
from math import (
ceil,
floor,
log2,
)
from typing import TYPE_CHECKING
import warnings

Expand Down Expand Up @@ -126,9 +130,7 @@ def _get_layout(
try:
return layouts[nplots]
except KeyError:
k = 1
while k**2 < nplots:
k += 1
k = floor(log2(nplots))

if (k - 1) * k >= nplots:
return k, (k - 1)
Expand Down
10 changes: 4 additions & 6 deletions pandas/tseries/holiday.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ def next_workday(dt: datetime) -> datetime:
returns next workday used for observances
"""
dt += timedelta(days=1)
while dt.weekday() > 4:
# Mon-Fri are 0-4
dt += timedelta(days=1)
# Mon-Fri are 0-4
dt += timedelta(days=max(dt.weekday() - 4, 0))
return dt


Expand All @@ -127,9 +126,8 @@ def previous_workday(dt: datetime) -> datetime:
returns previous workday used for observances
"""
dt -= timedelta(days=1)
while dt.weekday() > 4:
# Mon-Fri are 0-4
dt -= timedelta(days=1)
# Mon-Fri are 0-4
dt -= timedelta(days=max(dt.weekday() - 4, 0))
return dt


Expand Down

0 comments on commit 2580e0a

Please sign in to comment.