File tree 1 file changed +6
-16
lines changed
1 file changed +6
-16
lines changed Original file line number Diff line number Diff line change @@ -4153,7 +4153,8 @@ def reindex(
4153
4153
preserve_names = not hasattr (target , "name" )
4154
4154
4155
4155
# 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 )
4157
4158
4158
4159
if not isinstance (target , Index ) and len (target ) == 0 :
4159
4160
if level is not None and self ._is_multi :
@@ -7568,21 +7569,9 @@ def ensure_index(index_like: Axes, copy: bool = False) -> Index:
7568
7569
return Index (index_like , copy = copy )
7569
7570
7570
7571
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
-
7583
7572
def trim_front (strings : list [str ]) -> list [str ]:
7584
7573
"""
7585
- Trims zeros and decimal points .
7574
+ Trims leading spaces evenly among all strings .
7586
7575
7587
7576
Examples
7588
7577
--------
@@ -7594,8 +7583,9 @@ def trim_front(strings: list[str]) -> list[str]:
7594
7583
"""
7595
7584
if not strings :
7596
7585
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 ]
7599
7589
return strings
7600
7590
7601
7591
You can’t perform that action at this time.
0 commit comments