File tree Expand file tree Collapse file tree 1 file changed +6
-16
lines changed Expand file tree Collapse file tree 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 :
@@ -7564,21 +7565,9 @@ def ensure_index(index_like: Axes, copy: bool = False) -> Index:
7564
7565
return Index (index_like , copy = copy )
7565
7566
7566
7567
7567
- def ensure_has_len (seq ):
7568
- """
7569
- If seq is an iterator, put its values into a list.
7570
- """
7571
- try :
7572
- len (seq )
7573
- except TypeError :
7574
- return list (seq )
7575
- else :
7576
- return seq
7577
-
7578
-
7579
7568
def trim_front (strings : list [str ]) -> list [str ]:
7580
7569
"""
7581
- Trims zeros and decimal points .
7570
+ Trims leading spaces evenly among all strings .
7582
7571
7583
7572
Examples
7584
7573
--------
@@ -7590,8 +7579,9 @@ def trim_front(strings: list[str]) -> list[str]:
7590
7579
"""
7591
7580
if not strings :
7592
7581
return strings
7593
- while all (strings ) and all (x [0 ] == " " for x in strings ):
7594
- strings = [x [1 :] for x in strings ]
7582
+ smallest_leading_space = min (len (x ) - len (x .lstrip ()) for x in strings )
7583
+ if smallest_leading_space > 0 :
7584
+ strings = [x [smallest_leading_space :] for x in strings ]
7595
7585
return strings
7596
7586
7597
7587
You can’t perform that action at this time.
0 commit comments