@@ -697,68 +697,70 @@ def _pivot_longer_names_pattern_sequence(
697
697
"column labels assigned to the dataframe's index parameter. "
698
698
"Kindly use unique labels."
699
699
)
700
- outcome = df .columns
700
+ values = df .columns
701
701
702
702
mapping = [
703
- outcome .str .contains (regex , na = False , regex = True )
703
+ values .str .contains (regex , na = False , regex = True )
704
704
for regex in names_pattern
705
705
]
706
706
707
- outcome = (arr .any () for arr in mapping )
707
+ values = (arr .any () for arr in mapping )
708
708
# within each match, check the individual matches
709
709
# and raise an error if any is False
710
- for position , boolean in enumerate (outcome ):
710
+ for position , boolean in enumerate (values ):
711
711
if not boolean .item ():
712
712
raise ValueError (
713
713
"No match was returned for the regex "
714
714
f"at position { position } -> { names_pattern [position ]} ."
715
715
)
716
716
717
717
if values_to_is_a_sequence :
718
- mapping , values = np .select (mapping , values_to , None ), np .select (
718
+ mapping , outcome = np .select (mapping , values_to , None ), np .select (
719
719
mapping , names_to , None
720
720
)
721
721
else :
722
722
mapping = np .select (mapping , names_to , None )
723
723
724
724
# only matched columns are retained
725
- outcome = pd .notna (mapping )
726
- df = df .loc [:, outcome ]
727
- mapping = mapping [outcome ]
725
+ values = pd .notna (mapping )
726
+ df = df .loc [:, values ]
727
+ mapping = mapping [values ]
728
728
if values_to_is_a_sequence :
729
729
names_to = zip (names_to , values_to )
730
730
names_to = [* chain .from_iterable (names_to )]
731
731
if index :
732
732
names_to = [* index ] + names_to
733
- values = values [ outcome ]
733
+ outcome = outcome [ values ]
734
734
arr = defaultdict (list )
735
- for label , name in zip (values , df .columns ):
735
+ for label , name in zip (outcome , df .columns ):
736
736
arr [label ].append (name )
737
- values = arr .keys ()
737
+ outcome = arr .keys ()
738
738
arr = (entry for _ , entry in arr .items ())
739
739
arr = zip (* zip_longest (* arr ))
740
740
arr = map (pd .Series , arr )
741
- values = zip (values , arr )
741
+ outcome = zip (outcome , arr )
742
742
if names_transform :
743
- values = _names_transform (
744
- names_transform , is_dataframe = False , values = values
743
+ outcome = _names_transform (
744
+ names_transform , is_dataframe = False , values = outcome
745
745
)
746
- values = {name : arr ._values .repeat (len_index ) for name , arr in values }
746
+ outcome = {
747
+ name : arr ._values .repeat (len_index ) for name , arr in outcome
748
+ }
747
749
748
750
else :
749
- values = {}
751
+ outcome = {}
750
752
names_to = None
751
753
752
754
mapping = pd .Series (mapping )
753
- outcome , group_max = _headers_single_series (df = df , mapping = mapping )
755
+ values , group_max = _headers_single_series (df = df , mapping = mapping )
754
756
755
757
df = _final_frame_longer (
756
758
df = df ,
757
759
len_index = len_index ,
758
760
reps = group_max ,
759
761
index = index ,
760
- outcome = values ,
761
- values = outcome ,
762
+ outcome = outcome ,
763
+ values = values ,
762
764
names_to = names_to ,
763
765
dropna = dropna ,
764
766
sort_by_appearance = sort_by_appearance ,
0 commit comments