Skip to content

Commit 329fdaa

Browse files
dsm054jreback
authored andcommitted
TST: Verify that positional shifting works with duplicate columns (#9092) (#16810)
1 parent e5fd3e0 commit 329fdaa

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pandas/tests/frame/test_timeseries.py

+22
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,28 @@ def test_shift_empty(self):
266266

267267
assert_frame_equal(df, rs)
268268

269+
def test_shift_duplicate_columns(self):
270+
# GH 9092; verify that position-based shifting works
271+
# in the presence of duplicate columns
272+
column_lists = [list(range(5)), [1] * 5, [1, 1, 2, 2, 1]]
273+
data = np.random.randn(20, 5)
274+
275+
shifted = []
276+
for columns in column_lists:
277+
df = pd.DataFrame(data.copy(), columns=columns)
278+
for s in range(5):
279+
df.iloc[:, s] = df.iloc[:, s].shift(s + 1)
280+
df.columns = range(5)
281+
shifted.append(df)
282+
283+
# sanity check the base case
284+
nulls = shifted[0].isnull().sum()
285+
assert_series_equal(nulls, Series(range(1, 6), dtype='int64'))
286+
287+
# check all answers are the same
288+
assert_frame_equal(shifted[0], shifted[1])
289+
assert_frame_equal(shifted[0], shifted[2])
290+
269291
def test_tshift(self):
270292
# PeriodIndex
271293
ps = tm.makePeriodFrame()

0 commit comments

Comments
 (0)