Skip to content

Commit c47296a

Browse files
authored
CLN: indexes/base.py (#59928)
CLN: indexes.base.py
1 parent 198ed86 commit c47296a

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

pandas/core/indexes/base.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -4153,7 +4153,8 @@ def reindex(
41534153
preserve_names = not hasattr(target, "name")
41544154

41554155
# GH7774: preserve dtype/tz if target is empty and not an Index.
4156-
target = ensure_has_len(target) # target may be an iterator
4156+
if is_iterator(target):
4157+
target = list(target)
41574158

41584159
if not isinstance(target, Index) and len(target) == 0:
41594160
if level is not None and self._is_multi:
@@ -7568,21 +7569,9 @@ def ensure_index(index_like: Axes, copy: bool = False) -> Index:
75687569
return Index(index_like, copy=copy)
75697570

75707571

7571-
def ensure_has_len(seq):
7572-
"""
7573-
If seq is an iterator, put its values into a list.
7574-
"""
7575-
try:
7576-
len(seq)
7577-
except TypeError:
7578-
return list(seq)
7579-
else:
7580-
return seq
7581-
7582-
75837572
def trim_front(strings: list[str]) -> list[str]:
75847573
"""
7585-
Trims zeros and decimal points.
7574+
Trims leading spaces evenly among all strings.
75867575
75877576
Examples
75887577
--------
@@ -7594,8 +7583,9 @@ def trim_front(strings: list[str]) -> list[str]:
75947583
"""
75957584
if not strings:
75967585
return strings
7597-
while all(strings) and all(x[0] == " " for x in strings):
7598-
strings = [x[1:] for x in strings]
7586+
smallest_leading_space = min(len(x) - len(x.lstrip()) for x in strings)
7587+
if smallest_leading_space > 0:
7588+
strings = [x[smallest_leading_space:] for x in strings]
75997589
return strings
76007590

76017591

0 commit comments

Comments
 (0)