Skip to content

DOCS: remove outdated PeriodDtype.from_date_offset comment, use DateOffset instead of BaseOffset in docstrings #61096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1752,9 +1752,6 @@ cdef class _Period(PeriodMixin):
def __cinit__(self, int64_t ordinal, BaseOffset freq):
self.ordinal = ordinal
self.freq = freq
# Note: this is more performant than PeriodDtype.from_date_offset(freq)
# because from_date_offset cannot be made a cdef method (until cython
# supported cdef classmethods)
self._dtype = PeriodDtypeBase(freq._period_dtype_code, freq.n)

@classmethod
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2974,8 +2974,7 @@ def _delegate_method(self, name: str, *args, **kwargs):
from pandas import Series

method = getattr(self._parent, name)
res = method(*args, **kwargs)
if res is not None:
if (res := method(*args, **kwargs)) is not None:
return Series(res, index=self._index, name=self._name)


Expand Down
3 changes: 1 addition & 2 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ def __sizeof__(self) -> int:
Generates the total memory usage for an object that returns
either a value or Series of values
"""
memory_usage = getattr(self, "memory_usage", None)
if memory_usage:
if (memory_usage := getattr(self, "memory_usage", None)):
mem = memory_usage(deep=True)
return int(mem if is_scalar(mem) else mem.sum())

Expand Down
3 changes: 1 addition & 2 deletions pandas/core/computation/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ def _check_ne_builtin_clash(expr: Expr) -> None:
Terms can contain
"""
names = expr.names
overlap = names & _ne_builtins

if overlap:
if (overlap := names & _ne_builtins):
s = ", ".join([repr(x) for x in overlap])
raise NumExprClobberingError(
f'Variables in expression "{expr}" overlap with builtins: ({s})'
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1819,8 +1819,7 @@ def pandas_dtype(dtype) -> DtypeObj:
return StringDtype(na_value=np.nan)

# registered extension types
result = registry.find(dtype)
if result is not None:
if (result := registry.find(dtype)) is not None:
if isinstance(result, type):
# GH 31356, GH 54592
warnings.warn(
Expand Down
6 changes: 2 additions & 4 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,7 @@ def construct_from_string(cls, string: str_type) -> DatetimeTZDtype:
)

msg = f"Cannot construct a 'DatetimeTZDtype' from '{string}'"
match = cls._match.match(string)
if match:
if (match := cls._match.match(string)):
d = match.groupdict()
try:
return cls(unit=d["unit"], tz=d["tz"])
Expand Down Expand Up @@ -1999,9 +1998,8 @@ def _parse_subtype(dtype: str) -> tuple[str, bool]:
When the subtype cannot be extracted.
"""
xpr = re.compile(r"Sparse\[(?P<subtype>[^,]*)(, )?(?P<fill_value>.*?)?\]$")
m = xpr.match(dtype)
has_fill_value = False
if m:
if (m := xpr.match(dtype)):
subtype = m.groupdict()["subtype"]
has_fill_value = bool(m.groupdict()["fill_value"])
elif dtype == "Sparse":
Expand Down
6 changes: 2 additions & 4 deletions pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,7 @@ def __init__(
# we have a single grouper which may be a myriad of things,
# some of which are dependent on the passing in level

ilevel = self._ilevel
if ilevel is not None:
if (ilevel := self._ilevel) is not None:
# In extant tests, the new self.grouping_vector matches
# `index.get_level_values(ilevel)` whenever
# mapper is None and isinstance(index, MultiIndex)
Expand Down Expand Up @@ -547,8 +546,7 @@ def _passed_categorical(self) -> bool:

@cache_readonly
def name(self) -> Hashable:
ilevel = self._ilevel
if ilevel is not None:
if (ilevel := self._ilevel) is not None:
return self._index.names[ilevel]

if isinstance(self._orig_grouper, (Index, Series)):
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,8 @@ def size(self) -> Series:
Compute group sizes.
"""
ids = self.ids
ngroups = self.ngroups
out: np.ndarray | list
if ngroups:
if (ngroups := self.ngroups):
out = np.bincount(ids[ids != -1], minlength=ngroups)
else:
out = []
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6108,9 +6108,8 @@ def _raise_if_missing(self, key, indexer, axis_name: str_t) -> None:

# Count missing values
missing_mask = indexer < 0
nmissing = missing_mask.sum()

if nmissing:
if (nmissing := missing_mask.sum()):
if nmissing == len(indexer):
raise KeyError(f"None of [{key}] are in the [{axis_name}]")

Expand Down
9 changes: 3 additions & 6 deletions pandas/core/interchange/from_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ def _from_dataframe(df: DataFrameXchg, allow_copy: bool = True) -> pd.DataFrame:
else:
pandas_df = pd.concat(pandas_dfs, axis=0, ignore_index=True, copy=False)

index_obj = df.metadata.get("pandas.index", None)
if index_obj is not None:
if (index_obj := df.metadata.get("pandas.index", None)) is not None:
pandas_df.index = index_obj

return pandas_df
Expand Down Expand Up @@ -372,8 +371,7 @@ def string_column_to_ndarray(col: Column) -> tuple[np.ndarray, Any]:
def parse_datetime_format_str(format_str, data) -> pd.Series | np.ndarray:
"""Parse datetime `format_str` to interpret the `data`."""
# timestamp 'ts{unit}:tz'
timestamp_meta = re.match(r"ts([smun]):(.*)", format_str)
if timestamp_meta:
if (timestamp_meta := re.match(r"ts([smun]):(.*)", format_str)):
unit, tz = timestamp_meta.group(1), timestamp_meta.group(2)
if unit != "s":
# the format string describes only a first letter of the unit, so
Expand All @@ -386,8 +384,7 @@ def parse_datetime_format_str(format_str, data) -> pd.Series | np.ndarray:
return data

# date 'td{Days/Ms}'
date_meta = re.match(r"td([Dm])", format_str)
if date_meta:
if (date_meta := re.match(r"td([Dm])", format_str)):
unit = date_meta.group(1)
if unit == "D":
# NumPy doesn't support DAY unit, so converting days to seconds
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/strings/object_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,7 @@ def g(x):
def f(x):
if not isinstance(x, str):
return empty_row
m = regex.search(x)
if m:
if (m := regex.search(x)):
return [na_value if item is None else item for item in m.groups()]
else:
return empty_row
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,7 @@ def _apply(
codes = self._grouper.codes
levels = copy.copy(self._grouper.levels)

group_indices = self._grouper.indices.values()
if group_indices:
if (group_indices := self._grouper.indices.values()):
indexer = np.concatenate(list(group_indices))
else:
indexer = np.array([], dtype=np.intp)
Expand Down
Loading