From baab7bb71d71cabc50d1284c3abb45b39ad289cf Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 1 Jun 2021 14:15:05 -0700 Subject: [PATCH] CLN: assorted follow-ups --- doc/source/whatsnew/v1.3.0.rst | 1 + pandas/_libs/lib.pyx | 2 +- pandas/core/algorithms.py | 6 +++--- pandas/core/arrays/datetimes.py | 1 - pandas/core/arrays/period.py | 4 ++-- pandas/core/indexes/base.py | 2 ++ 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 409125b6d6691..1556c88aaecc6 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -643,6 +643,7 @@ Other API changes - Partially initialized :class:`CategoricalDtype` (i.e. those with ``categories=None`` objects will no longer compare as equal to fully initialized dtype objects. - Accessing ``_constructor_expanddim`` on a :class:`DataFrame` and ``_constructor_sliced`` on a :class:`Series` now raise an ``AttributeError``. Previously a ``NotImplementedError`` was raised (:issue:`38782`) - Added new ``engine`` and ``**engine_kwargs`` parameters to :meth:`DataFrame.to_sql` to support other future "SQL engines". Currently we still only use ``SQLAlchemy`` under the hood, but more engines are planned to be supported such as ``turbodbc`` (:issue:`36893`) +- Removed redundant ``freq`` from :class:`PeriodIndex` string representation (:issue:`41653`) Build ===== diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 6a270c0a55638..e2883dbf4c76b 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -1461,7 +1461,7 @@ def infer_dtype(value: object, skipna: bool = True) -> str: for i in range(n): val = values[i] - # do not use is_nul_datetimelike to keep + # do not use is_null_datetimelike to keep # np.datetime64('nat') and np.timedelta64('nat') if val is None or util.is_nan(val): pass diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index f8f5e5e05bc35..30f42435ad177 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1266,14 +1266,14 @@ def compute(self, method: str) -> Series: return dropped.sort_values(ascending=ascending).head(n) # fast method - arr, pandas_dtype = _ensure_data(dropped.values) + arr, new_dtype = _ensure_data(dropped.values) if method == "nlargest": arr = -arr - if is_integer_dtype(pandas_dtype): + if is_integer_dtype(new_dtype): # GH 21426: ensure reverse ordering at boundaries arr -= 1 - elif is_bool_dtype(pandas_dtype): + elif is_bool_dtype(new_dtype): # GH 26154: ensure False is smaller than True arr = 1 - (-arr) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index ec69d9ccbdd90..020f708606353 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -2104,7 +2104,6 @@ def sequence_to_dt64ns( result = data.view(DT64NS_DTYPE) if copy: - # TODO: should this be deepcopy? result = result.copy() assert isinstance(result, np.ndarray), type(result) diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index c2323c8697eee..d8c1b9cef468a 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -866,7 +866,7 @@ def start_time(self) -> DatetimeArray: def end_time(self) -> DatetimeArray: return self.to_timestamp(how="end") - def _require_matching_freq(self, other, base=False): + def _require_matching_freq(self, other, base: bool = False) -> None: # See also arrays.period.raise_on_incompatible if isinstance(other, BaseOffset): other_freq = other @@ -1057,7 +1057,7 @@ def dt64arr_to_periodarr(data, freq, tz=None): Returns ------- - ordinals : ndarray[int] + ordinals : ndarray[int64] freq : Tick The frequency extracted from the Series or DatetimeIndex if that's used. diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 30215b40593d3..eb203d349b4e7 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -776,6 +776,7 @@ def _engine(self) -> libindex.IndexEngine: target_values = self._get_engine_target() return self._engine_type(lambda: target_values, len(self)) + @final @cache_readonly def _dir_additions_for_owner(self) -> set[str_t]: """ @@ -6209,6 +6210,7 @@ def shape(self) -> Shape: # See GH#27775, GH#27384 for history/reasoning in how this is defined. return (len(self),) + @final def _deprecated_arg(self, value, name: str_t, methodname: str_t) -> None: """ Issue a FutureWarning if the arg/kwarg is not no_default.