Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: support dataframe.loc with conditional columns selection #233

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 5 commits into from
Dec 11, 2023
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
7 changes: 6 additions & 1 deletion 7 bigframes/core/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ def __getitem__(self, key):
bigframes.dataframe.DataFrame,
_loc_getitem_series_or_dataframe(self._dataframe, key[0]),
)
return df[key[1]]

columns = key[1]
if isinstance(columns, pd.Series) and columns.dtype == "bool":
columns = df.columns[columns]

return df[columns]

return typing.cast(
bigframes.dataframe.DataFrame,
Expand Down
11 changes: 11 additions & 0 deletions 11 tests/system/small/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2474,6 +2474,17 @@ def test_loc_select_column(scalars_df_index, scalars_pandas_df_index):
)


def test_loc_select_with_column_condition(scalars_df_index, scalars_pandas_df_index):
bf_result = scalars_df_index.loc[:, scalars_df_index.dtypes == "Int64"].to_pandas()
pd_result = scalars_pandas_df_index.loc[
:, scalars_pandas_df_index.dtypes == "Int64"
]
pd.testing.assert_frame_equal(
bf_result,
pd_result,
)


def test_loc_single_index_with_duplicate(scalars_df_index, scalars_pandas_df_index):
scalars_df_index = scalars_df_index.set_index("string_col", drop=False)
scalars_pandas_df_index = scalars_pandas_df_index.set_index(
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.