Skip to content

feat: Allow df.drop to take an index object #68

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

Merged
merged 22 commits into from
Oct 4, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add first implementation for df.drop(index)
  • Loading branch information
Henry J Solberg committed Sep 28, 2023
commit 0fc8dd76d84cc6013a65d123e4d4ac4b3d961902
21 changes: 16 additions & 5 deletions bigframes/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,11 +917,22 @@ def drop(
inverse_condition_id, ops.invert_op
)
elif isinstance(index, indexes.Index):
# idea: make a value column with the same values as index
# align index with self so that the new value column is NA
# for rows that weren't in index originally
# then filter by the index's value column == self index
pass
block = index._data._get_block()
original_value_columns = block.value_columns
block = blocks.Block(block._expr, [], block._expr.column_names.keys())
level_names = ["level_" + str(n) for n in range(index.nlevels)]
block = block.set_index(level_names, drop=False)
index_df = DataFrame(block)
index_df = index_df.drop(columns=original_value_columns)
df_with_indices_to_drop = self.join(index_df)
bool_series = df_with_indices_to_drop["level_0"].isna()
for i in range(1, index.nlevels):
bool_series = (
bool_series & df_with_indices_to_drop[level_names[i]].isna()
)
result = df_with_indices_to_drop[bool_series]
result = result.drop(columns=level_names)
return result
else:
block, condition_id = block.apply_unary_op(
level_id, ops.partial_right(ops.ne_op, index)
Expand Down