8000 fix: Fix a bug that raises exception when re-indexing columns with th… by sycai · Pull Request #988 · googleapis/python-bigquery-dataframes · GitHub
[go: up one dir, main page]

Skip to content
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
5 changes: 5 additions & 0 deletions bigframes/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,11 @@ def _reindex_rows(
def _reindex_columns(self, columns):
block = self._block
new_column_index, indexer = self.columns.reindex(columns)

if indexer is None:
# The new index is the same as the old one. Do nothing.
return self

result_cols = []
for label, index in zip(columns, indexer):
if index >= 0:
Expand Down
15 changes: 15 additions & 0 deletions tests/system/small/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3664,6 +3664,21 @@ def test_df_reindex_columns(scalars_df_index, scalars_pandas_df_index):
)


def test_df_reindex_columns_with_same_order(scalars_df_index, scalars_pandas_df_index):
# First, make sure the two dataframes have the same columns in order.
columns = ["int64_col", "int64_too"]
bf = scalars_df_index[columns]
pd_df = scalars_pandas_df_index[columns]

bf_result = bf.reindex(columns=columns).to_pandas()
pd_result = pd_df.reindex(columns=columns)

pd.testing.assert_frame_equal(
bf_result,
pd_result,
)


def test_df_equals_identical(scalars_df_index, scalars_pandas_df_index):
unsupported = [
"geography_col",
Expand Down
0