Skip to content

Commit e335a70

Browse files
committed
proper renaming of variables
1 parent 7ffba06 commit e335a70

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

janitor/functions/pivot.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -697,68 +697,70 @@ def _pivot_longer_names_pattern_sequence(
697697
"column labels assigned to the dataframe's index parameter. "
698698
"Kindly use unique labels."
699699
)
700-
outcome = df.columns
700+
values = df.columns
701701

702702
mapping = [
703-
outcome.str.contains(regex, na=False, regex=True)
703+
values.str.contains(regex, na=False, regex=True)
704704
for regex in names_pattern
705705
]
706706

707-
outcome = (arr.any() for arr in mapping)
707+
values = (arr.any() for arr in mapping)
708708
# within each match, check the individual matches
709709
# and raise an error if any is False
710-
for position, boolean in enumerate(outcome):
710+
for position, boolean in enumerate(values):
711711
if not boolean.item():
712712
raise ValueError(
713713
"No match was returned for the regex "
714714
f"at position {position} -> {names_pattern[position]}."
715715
)
716716

717717
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(
719719
mapping, names_to, None
720720
)
721721
else:
722722
mapping = np.select(mapping, names_to, None)
723723

724724
# 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]
728728
if values_to_is_a_sequence:
729729
names_to = zip(names_to, values_to)
730730
names_to = [*chain.from_iterable(names_to)]
731731
if index:
732732
names_to = [*index] + names_to
733-
values = values[outcome]
733+
outcome = outcome[values]
734734
arr = defaultdict(list)
735-
for label, name in zip(values, df.columns):
735+
for label, name in zip(outcome, df.columns):
736736
arr[label].append(name)
737-
values = arr.keys()
737+
outcome = arr.keys()
738738
arr = (entry for _, entry in arr.items())
739739
arr = zip(*zip_longest(*arr))
740740
arr = map(pd.Series, arr)
741-
values = zip(values, arr)
741+
outcome = zip(outcome, arr)
742742
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
745745
)
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+
}
747749

748750
else:
749-
values = {}
751+
outcome = {}
750752
names_to = None
751753

752754
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)
754756

755757
df = _final_frame_longer(
756758
df=df,
757759
len_index=len_index,
758760
reps=group_max,
759761
index=index,
760-
outcome=values,
761-
values=outcome,
762+
outcome=outcome,
763+
values=values,
762764
names_to=names_to,
763765
dropna=dropna,
764766
sort_by_appearance=sort_by_appearance,

0 commit comments

Comments
 (0)