Skip to content

Commit 87aa9fb

Browse files
author
Xuye (Chris) Qin
authored
[BACKPORT] Fix incorrect index_value in df.drop() (#1466) (#1488)
1 parent cb1651f commit 87aa9fb

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Diff for: mars/dataframe/base/drop.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def tile(cls, op: 'DataFrameDrop'):
117117
col_to_args[c.index[1]] = (new_dtypes, new_col_id)
118118

119119
params.update(dict(dtypes=new_dtypes, index=(c.index[0], new_col_id),
120-
index_value=parse_index(None, (c.key, c.index_value.key))))
120+
index_value=c.index_value))
121121
if op.index is not None:
122122
params.update(dict(shape=(np.nan, len(new_dtypes)),
123123
index_value=parse_index(None, (c.key, c.index_value.key))))

Diff for: mars/dataframe/base/tests/test_base.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -785,13 +785,25 @@ def testDrop(self):
785785
raw = pd.DataFrame(rs.randint(1000, size=(20, 8)),
786786
columns=['c' + str(i + 1) for i in range(8)])
787787

788-
df = from_pandas_df(raw, chunk_size=3)
788+
df = from_pandas_df(raw, chunk_size=8)
789789

790790
with self.assertRaises(KeyError):
791791
df.drop(columns=['c9'])
792792
with self.assertRaises(NotImplementedError):
793793
df.drop(columns=from_pandas_series(pd.Series(['c9'])))
794794

795+
r = df.drop(columns=['c1'])
796+
pd.testing.assert_index_equal(r.index_value.to_pandas(), raw.index)
797+
798+
tiled = r.tiles()
799+
start = 0
800+
for c in tiled.chunks:
801+
raw_index = raw.index[start: start + c.shape[0]]
802+
start += c.shape[0]
803+
pd.testing.assert_index_equal(raw_index, c.index_value.to_pandas())
804+
805+
df = from_pandas_df(raw, chunk_size=3)
806+
795807
columns = ['c2', 'c4', 'c5', 'c6']
796808
index = [3, 6, 7]
797809
r = df.drop(columns=columns, index=index)

0 commit comments

Comments
 (0)