Skip to content

Commit 596b03b

Browse files
authored
fix: Fix a bug that raises exception when re-indexing columns with their original order (#988)
1 parent 89ea44f commit 596b03b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

bigframes/dataframe.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,11 @@ def _reindex_rows(
19131913
def _reindex_columns(self, columns):
19141914
block = self._block
19151915
new_column_index, indexer = self.columns.reindex(columns)
1916+
1917+
if indexer is None:
1918+
# The new index is the same as the old one. Do nothing.
1919+
return self
1920+
19161921
result_cols = []
19171922
for label, index in zip(columns, indexer):
19181923
if index >= 0:

tests/system/small/test_dataframe.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3664,6 +3664,21 @@ def test_df_reindex_columns(scalars_df_index, scalars_pandas_df_index):
36643664
)
36653665

36663666

3667+
def test_df_reindex_columns_with_same_order(scalars_df_index, scalars_pandas_df_index):
3668+
# First, make sure the two dataframes have the same columns in order.
3669+
columns = ["int64_col", "int64_too"]
3670+
bf = scalars_df_index[columns]
3671+
pd_df = scalars_pandas_df_index[columns]
3672+
3673+
bf_result = bf.reindex(columns=columns).to_pandas()
3674+
pd_result = pd_df.reindex(columns=columns)
3675+
3676+
pd.testing.assert_frame_equal(
3677+
bf_result,
3678+
pd_result,
3679+
)
3680+
3681+
36673682
def test_df_equals_identical(scalars_df_index, scalars_pandas_df_index):
36683683
unsupported = [
36693684
"geography_col",

0 commit comments

Comments
 (0)