diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py index 05e1a36877e06..5ec4de4ee792b 100644 --- a/pandas/core/strings/accessor.py +++ b/pandas/core/strings/accessor.py @@ -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 @@ -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): diff --git a/pandas/plotting/_matplotlib/tools.py b/pandas/plotting/_matplotlib/tools.py index d5624aecd1215..5ebbdf886eb32 100644 --- a/pandas/plotting/_matplotlib/tools.py +++ b/pandas/plotting/_matplotlib/tools.py @@ -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 @@ -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) diff --git a/pandas/tseries/holiday.py b/pandas/tseries/holiday.py index bf4ec2e551f01..b9ef557cb1d15 100644 --- a/pandas/tseries/holiday.py +++ b/pandas/tseries/holiday.py @@ -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 @@ -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