Skip to content

Commit

Permalink
Properly retrieve last column when -1 is specified for column index (
Browse files Browse the repository at this point in the history
…#8529)

Closes #8501

This PR fixes the bug when indexing columns with -1 in `column_acccessor.select_by_index`, the last column is not properly retrieved.

Authors:
  - Michael Wang (https://github.com/isVoid)

Approvers:
  - Ashwin Srinath (https://github.com/shwina)
  - Charles Blackmon-Luca (https://github.com/charlesbluca)

URL: #8529
  • Loading branch information
isVoid authored Jun 16, 2021
1 parent 052f68e commit 2bbeac9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def select_by_index(self, index: Any) -> ColumnAccessor:
start, stop, step = index.indices(len(self._data))
keys = self.names[start:stop:step]
elif pd.api.types.is_integer(index):
keys = self.names[index : index + 1]
keys = [self.names[index]]
else:
keys = (self.names[i] for i in index)
data = {k: self._data[k] for k in keys}
Expand Down
8 changes: 2 additions & 6 deletions python/cudf/cudf/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,6 @@ def test_dataframe_iloc(nelem):
assert_eq(gdf.iloc[np.array([0])], pdf.loc[np.array([0])])


@pytest.mark.xfail(raises=AssertionError, reason="Series.index are different")
def test_dataframe_iloc_tuple():
gdf = cudf.DataFrame()
nelem = 123
Expand All @@ -674,11 +673,8 @@ def test_dataframe_iloc_tuple():
pdf["a"] = ha
pdf["b"] = hb

# We don't support passing the column names into the index quite yet
got = gdf.iloc[1, [1]]
expect = pdf.iloc[1, [1]]

assert_eq(got, expect)
assert_eq(gdf.iloc[1, [1]], pdf.iloc[1, [1]], check_dtype=False)
assert_eq(gdf.iloc[:, -1], pdf.iloc[:, -1])


@pytest.mark.xfail(
Expand Down

0 comments on commit 2bbeac9

Please sign in to comment.