Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up state variables in MultiIndex #16203

Merged
merged 15 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3593,15 +3593,15 @@ def rename(

if level is not None and isinstance(self.index, MultiIndex):
level = self.index._get_level_label(level)
out_index = self.index.copy(deep=copy)
level_values = out_index.get_level_values(level)
level_values.to_frame().replace(
level_values = self.index.get_level_values(level)
ca = self.index._data.copy(deep=copy)
ca[level] = level_values._column.find_and_replace(
to_replace=list(index.keys()),
value=list(index.values()),
inplace=True,
replacement=list(index.values()),
)
out_index = type(self.index)._from_data(
ca, name=self.index.name
)
out_index._data[level] = column.as_column(level_values)
out_index._compute_levels_and_codes()
else:
to_replace = list(index.keys())
vals = list(index.values())
Expand Down Expand Up @@ -7058,12 +7058,8 @@ def stack(self, level=-1, dropna=no_default, future_stack=False):
# Assemble the final index
new_index_columns = [*repeated_index._columns, *tiled_index]
index_names = [*self.index.names, *unique_named_levels.names]
new_index = MultiIndex.from_frame(
DataFrame._from_data(
dict(zip(range(0, len(new_index_columns)), new_index_columns))
),
names=index_names,
)
new_index = MultiIndex._from_data(dict(enumerate(new_index_columns)))
new_index.names = index_names

# Compute the column indices that serves as the input for
# `interleave_columns`
Expand Down
Loading
Loading