Skip to content

Commit 3f985b9

Browse files
authored
CLN: assorted; silence test warnings (#49426)
* CLN: assorted * revert * fix warning suppression
1 parent cd1af81 commit 3f985b9

File tree

23 files changed

+39
-98
lines changed

23 files changed

+39
-98
lines changed

pandas/_libs/tslibs/offsets.pyx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,12 +1058,6 @@ cdef class Tick(SingleConstructorOffset):
10581058

10591059
if util.is_timedelta64_object(other) or PyDelta_Check(other):
10601060
return other + self.delta
1061-
elif isinstance(other, type(self)):
1062-
# TODO(2.0): remove once apply deprecation is enforced.
1063-
# This is reached in tests that specifically call apply,
1064-
# but should not be reached "naturally" because __add__ should
1065-
# catch this case first.
1066-
return type(self)(self.n + other.n)
10671061

10681062
raise ApplyTypeError(f"Unhandled type: {type(other).__name__}")
10691063

pandas/core/arrays/datetimes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ def _from_sequence(cls, scalars, *, dtype=None, copy: bool = False):
292292
def _from_sequence_not_strict(
293293
cls,
294294
data,
295+
*,
295296
dtype=None,
296297
copy: bool = False,
297298
tz=lib.no_default,
@@ -300,6 +301,9 @@ def _from_sequence_not_strict(
300301
yearfirst: bool = False,
301302
ambiguous: TimeAmbiguous = "raise",
302303
):
304+
"""
305+
A non-strict version of _from_sequence, called from DatetimeIndex.__new__.
306+
"""
303307
explicit_none = freq is None
304308
freq = freq if freq is not lib.no_default else None
305309
freq, freq_infer = dtl.maybe_infer_freq(freq)
@@ -1976,7 +1980,6 @@ def _sequence_to_dt64ns(
19761980
yearfirst: bool = False,
19771981
ambiguous: TimeAmbiguous = "raise",
19781982
allow_mixed: bool = False,
1979-
require_iso8601: bool = False,
19801983
):
19811984
"""
19821985
Parameters
@@ -1990,8 +1993,6 @@ def _sequence_to_dt64ns(
19901993
See pandas._libs.tslibs.tzconversion.tz_localize_to_utc.
19911994
allow_mixed : bool, default False
19921995
Interpret integers as timestamps when datetime objects are also present.
1993-
require_iso8601 : bool, default False
1994-
Only consider ISO-8601 formats when parsing strings.
19951996
19961997
Returns
19971998
-------
@@ -2038,7 +2039,6 @@ def _sequence_to_dt64ns(
20382039
yearfirst=yearfirst,
20392040
allow_object=False,
20402041
allow_mixed=allow_mixed,
2041-
require_iso8601=require_iso8601,
20422042
)
20432043
if tz and inferred_tz:
20442044
# two timezones: convert to intended from base UTC repr

pandas/core/arrays/timedeltas.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,15 @@ def _from_sequence(cls, data, *, dtype=None, copy: bool = False) -> TimedeltaArr
215215
def _from_sequence_not_strict(
216216
cls,
217217
data,
218+
*,
218219
dtype=None,
219220
copy: bool = False,
220221
freq=lib.no_default,
221222
unit=None,
222223
) -> TimedeltaArray:
224+
"""
225+
A non-strict version of _from_sequence, called from TimedeltaIndex.__new__.
226+
"""
223227
if dtype:
224228
dtype = _validate_td64_dtype(dtype)
225229

@@ -296,7 +300,6 @@ def _unbox_scalar(self, value, setitem: bool = False) -> np.timedelta64:
296300
return np.timedelta64(value.value, "ns")
297301
else:
298302
return value._as_unit(self._unit).asm8
299-
return np.timedelta64(value.value, "ns")
300303

301304
def _scalar_from_string(self, value) -> Timedelta | NaTType:
302305
return Timedelta(value)

pandas/core/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ def _values(self) -> ExtensionArray | np.ndarray:
294294
# must be defined here as a property for mypy
295295
raise AbstractMethodError(self)
296296

297+
@final
297298
def transpose(self: _T, *args, **kwargs) -> _T:
298299
"""
299300
Return the transpose, which is by definition self.
@@ -330,6 +331,7 @@ def ndim(self) -> Literal[1]:
330331
"""
331332
return 1
332333

334+
@final
333335
def item(self):
334336
"""
335337
Return the first element of the underlying data as a Python scalar.
@@ -427,6 +429,7 @@ def array(self) -> ExtensionArray:
427429
"""
428430
raise AbstractMethodError(self)
429431

432+
@final
430433
def to_numpy(
431434
self,
432435
dtype: npt.DTypeLike | None = None,
@@ -542,6 +545,7 @@ def to_numpy(
542545
result[np.asanyarray(self.isna())] = na_value
543546
return result
544547

548+
@final
545549
@property
546550
def empty(self) -> bool:
547551
return not self.size
@@ -902,6 +906,7 @@ def _map_values(self, mapper, na_action=None):
902906

903907
return new_values
904908

909+
@final
905910
def value_counts(
906911
self,
907912
normalize: bool = False,
@@ -1006,6 +1011,7 @@ def unique(self):
10061011
result = unique1d(values)
10071012
return result
10081013

1014+
@final
10091015
def nunique(self, dropna: bool = True) -> int:
10101016
"""
10111017
Return number of unique elements in the object.
@@ -1103,6 +1109,7 @@ def is_monotonic_decreasing(self) -> bool:
11031109

11041110
return Index(self).is_monotonic_decreasing
11051111

1112+
@final
11061113
def _memory_usage(self, deep: bool = False) -> int:
11071114
"""
11081115
Memory usage of the values.

pandas/core/dtypes/astype.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ def astype_nansafe(
129129
return arr.view(dtype)
130130

131131
elif dtype.kind == "m":
132-
# TODO(2.0): change to use the same logic as TDA.astype, i.e.
133-
# giving the requested dtype for supported units (s, ms, us, ns)
132+
# give the requested dtype for supported units (s, ms, us, ns)
134133
# and doing the old convert-to-float behavior otherwise.
135134
if is_supported_unit(get_unit_from_dtype(arr.dtype)):
136135
from pandas.core.construction import ensure_wrapped_if_datetimelike

pandas/core/dtypes/cast.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
Dtype,
4242
DtypeObj,
4343
Scalar,
44+
npt,
4445
)
4546
from pandas.errors import (
4647
IntCastingNaNError,
@@ -1199,7 +1200,7 @@ def convert_dtypes(
11991200

12001201

12011202
def maybe_infer_to_datetimelike(
1202-
value: np.ndarray,
1203+
value: npt.NDArray[np.object_],
12031204
) -> np.ndarray | DatetimeArray | TimedeltaArray | PeriodArray | IntervalArray:
12041205
"""
12051206
we might have a array (or single object) that is datetime like,

pandas/core/groupby/base.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
from __future__ import annotations
55

66
import dataclasses
7-
from typing import (
8-
Hashable,
9-
Literal,
10-
)
7+
from typing import Hashable
118

129

1310
@dataclasses.dataclass(order=True, frozen=True)
@@ -61,15 +58,6 @@ class OutputKey:
6158
# produces a result that has the same shape as the group.
6259

6360

64-
# TODO(2.0) Remove after pad/backfill deprecation enforced
65-
def maybe_normalize_deprecated_kernels(kernel) -> Literal["bfill", "ffill"]:
66-
if kernel == "backfill":
67-
kernel = "bfill"
68-
elif kernel == "pad":
69-
kernel = "ffill"
70-
return kernel
71-
72-
7361
transformation_kernels = frozenset(
7462
[
7563
"bfill",

pandas/core/indexes/base.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5796,20 +5796,6 @@ def _should_fallback_to_positional(self) -> bool:
57965796
"""
57975797
return not self.holds_integer()
57985798

5799-
def _get_values_for_loc(self, series: Series, loc, key):
5800-
"""
5801-
Do a positional lookup on the given Series, returning either a scalar
5802-
or a Series.
5803-
5804-
Assumes that `series.index is self`
5805-
5806-
key is included for MultiIndex compat.
5807-
"""
5808-
if is_integer(loc):
5809-
return series._values[loc]
5810-
5811-
return series.iloc[loc]
5812-
58135799
_index_shared_docs[
58145800
"get_indexer_non_unique"
58155801
] = """
@@ -6802,6 +6788,7 @@ def _cmp_method(self, other, op):
68026788

68036789
return result
68046790

6791+
@final
68056792
def _construct_result(self, result, name):
68066793
if isinstance(result, tuple):
68076794
return (

pandas/core/indexes/multi.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,26 +2539,6 @@ def _should_fallback_to_positional(self) -> bool:
25392539
# GH#33355
25402540
return self.levels[0]._should_fallback_to_positional
25412541

2542-
def _get_values_for_loc(self, series: Series, loc, key):
2543-
"""
2544-
Do a positional lookup on the given Series, returning either a scalar
2545-
or a Series.
2546-
2547-
Assumes that `series.index is self`
2548-
"""
2549-
new_values = series._values[loc]
2550-
if is_scalar(loc):
2551-
return new_values
2552-
2553-
if len(new_values) == 1 and not self.nlevels > 1:
2554-
# If more than one level left, we can not return a scalar
2555-
return new_values[0]
2556-
2557-
new_index = self[loc]
2558-
new_index = maybe_droplevels(new_index, key)
2559-
new_ser = series._constructor(new_values, index=new_index, name=series.name)
2560-
return new_ser.__finalize__(series)
2561-
25622542
def _get_indexer_strict(
25632543
self, key, axis_name: str
25642544
) -> tuple[Index, npt.NDArray[np.intp]]:

pandas/core/series.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,13 +705,13 @@ def array(self) -> ExtensionArray:
705705
return self._mgr.array_values()
706706

707707
# ops
708-
def ravel(self, order: str = "C") -> np.ndarray:
708+
def ravel(self, order: str = "C") -> ArrayLike:
709709
"""
710-
Return the flattened underlying data as an ndarray.
710+
Return the flattened underlying data as an ndarray or ExtensionArray.
711711
712712
Returns
713713
-------
714-
numpy.ndarray or ndarray-like
714+
numpy.ndarray or ExtensionArray
715715
Flattened data of the Series.
716716
717717
See Also

0 commit comments

Comments
 (0)