Skip to content

Commit 8f2f14f

Browse files
jbrockmendelfeefladder
authored andcommitted
CLN: collected cleanups (pandas-dev#42827)
1 parent c98d004 commit 8f2f14f

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

pandas/core/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ def factorize(self, sort: bool = False, na_sentinel: int | None = -1):
12211221
"""
12221222

12231223
@doc(_shared_docs["searchsorted"], klass="Index")
1224-
def searchsorted(self, value, side="left", sorter=None) -> np.ndarray:
1224+
def searchsorted(self, value, side="left", sorter=None) -> npt.NDArray[np.intp]:
12251225
return algorithms.searchsorted(self._values, value, side=side, sorter=sorter)
12261226

12271227
def drop_duplicates(self, keep="first"):
@@ -1232,5 +1232,5 @@ def drop_duplicates(self, keep="first"):
12321232
@final
12331233
def _duplicated(
12341234
self, keep: Literal["first", "last", False] = "first"
1235-
) -> np.ndarray:
1235+
) -> npt.NDArray[np.bool_]:
12361236
return duplicated(self._values, keep=keep)

pandas/core/construction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def extract_array(
402402
>>> extract_array([1, 2, 3])
403403
[1, 2, 3]
404404
405-
For an ndarray-backed Series / Index a PandasArray is returned.
405+
For an ndarray-backed Series / Index the ndarray is returned.
406406
407407
>>> extract_array(pd.Series([1, 2, 3]))
408408
array([1, 2, 3])

pandas/core/indexes/datetimelike.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,11 @@ def _format_attrs(self):
238238
"""
239239
attrs = super()._format_attrs()
240240
for attrib in self._attributes:
241+
# iterating over _attributes prevents us from doing this for PeriodIndex
241242
if attrib == "freq":
242243
freq = self.freqstr
243244
if freq is not None:
244-
freq = repr(freq)
245+
freq = repr(freq) # e.g. D -> 'D'
245246
# Argument 1 to "append" of "list" has incompatible type
246247
# "Tuple[str, Optional[str]]"; expected "Tuple[str, Union[str, int]]"
247248
attrs.append(("freq", freq)) # type: ignore[arg-type]

pandas/core/indexing.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ def _get_setitem_indexer(self, key):
642642
self._ensure_listlike_indexer(key)
643643

644644
if self.axis is not None:
645-
return self._convert_tuple(key, is_setter=True)
645+
return self._convert_tuple(key)
646646

647647
ax = self.obj._get_axis(0)
648648

@@ -653,12 +653,12 @@ def _get_setitem_indexer(self, key):
653653

654654
if isinstance(key, tuple):
655655
with suppress(IndexingError):
656-
return self._convert_tuple(key, is_setter=True)
656+
return self._convert_tuple(key)
657657

658658
if isinstance(key, range):
659659
return list(key)
660660

661-
return self._convert_to_indexer(key, axis=0, is_setter=True)
661+
return self._convert_to_indexer(key, axis=0)
662662

663663
def _ensure_listlike_indexer(self, key, axis=None, value=None):
664664
"""
@@ -755,21 +755,19 @@ def _is_nested_tuple_indexer(self, tup: tuple) -> bool:
755755
return any(is_nested_tuple(tup, ax) for ax in self.obj.axes)
756756
return False
757757

758-
def _convert_tuple(self, key, is_setter: bool = False):
758+
def _convert_tuple(self, key):
759759
keyidx = []
760760
if self.axis is not None:
761761
axis = self.obj._get_axis_number(self.axis)
762762
for i in range(self.ndim):
763763
if i == axis:
764-
keyidx.append(
765-
self._convert_to_indexer(key, axis=axis, is_setter=is_setter)
766-
)
764+
keyidx.append(self._convert_to_indexer(key, axis=axis))
767765
else:
768766
keyidx.append(slice(None))
769767
else:
770768
self._validate_key_length(key)
771769
for i, k in enumerate(key):
772-
idx = self._convert_to_indexer(k, axis=i, is_setter=is_setter)
770+
idx = self._convert_to_indexer(k, axis=i)
773771
keyidx.append(idx)
774772

775773
return tuple(keyidx)
@@ -867,8 +865,8 @@ def _getitem_nested_tuple(self, tup: tuple):
867865
# a tuple passed to a series with a multi-index
868866
if len(tup) > self.ndim:
869867
if self.name != "loc":
870-
# This should never be reached, but lets be explicit about it
871-
raise ValueError("Too many indices")
868+
# This should never be reached, but let's be explicit about it
869+
raise ValueError("Too many indices") # pragma: no cover
872870
if all(is_hashable(x) or com.is_null_slice(x) for x in tup):
873871
# GH#10521 Series should reduce MultiIndex dimensions instead of
874872
# DataFrame, IndexingError is not raised when slice(None,None,None)
@@ -911,7 +909,7 @@ def _getitem_nested_tuple(self, tup: tuple):
911909

912910
return obj
913911

914-
def _convert_to_indexer(self, key, axis: int, is_setter: bool = False):
912+
def _convert_to_indexer(self, key, axis: int):
915913
raise AbstractMethodError(self)
916914

917915
def __getitem__(self, key):
@@ -1176,7 +1174,7 @@ def _get_slice_axis(self, slice_obj: slice, axis: int):
11761174
# return a DatetimeIndex instead of a slice object.
11771175
return self.obj.take(indexer, axis=axis)
11781176

1179-
def _convert_to_indexer(self, key, axis: int, is_setter: bool = False):
1177+
def _convert_to_indexer(self, key, axis: int):
11801178
"""
11811179
Convert indexing key into something we can use to do actual fancy
11821180
indexing on a ndarray.
@@ -1486,7 +1484,7 @@ def _get_slice_axis(self, slice_obj: slice, axis: int):
14861484
labels._validate_positional_slice(slice_obj)
14871485
return self.obj._slice(slice_obj, axis=axis)
14881486

1489-
def _convert_to_indexer(self, key, axis: int, is_setter: bool = False):
1487+
def _convert_to_indexer(self, key, axis: int):
14901488
"""
14911489
Much simpler as we only have to deal with our valid types.
14921490
"""

pandas/core/internals/concat.py

+1
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ def _combine_concat_plans(plans, concat_axis: int):
672672
offset += last_plc.as_slice.stop
673673

674674
else:
675+
# singleton list so we can modify it as a side-effect within _next_or_none
675676
num_ended = [0]
676677

677678
def _next_or_none(seq):

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4385,7 +4385,7 @@ def _reduce(
43854385
return op(delegate, skipna=skipna, **kwds)
43864386

43874387
def _reindex_indexer(
4388-
self, new_index: Index | None, indexer: np.ndarray | None, copy: bool
4388+
self, new_index: Index | None, indexer: npt.NDArray[np.intp] | None, copy: bool
43894389
) -> Series:
43904390
# Note: new_index is None iff indexer is None
43914391
# if not None, indexer is np.intp

0 commit comments

Comments
 (0)